RE: Re: Optional args in C code.

"Michael Geary" <[email protected]> Mon, 3 May 2004 17:09:57 -0700
Newsgroups gmane.comp.lang.prothon.devel
Message-ID <[email protected]>
> My default VC setup allows // but not embedded
> declarations. What standard is that?

// is definitely not in ANSI C, but it's widely available. It *almost* made
it into the ANSI C standard. <sigh>

I hate /* */ comments, so much that if it were my project and I were using
C, I would go ahead and use // comments. Then, the first time I ran into a
compiler that didn't support them, I would write a preprocessor to convert
// comments to /* */ in a temp C file as part of the build process.

Too bad about having to put declarations at the beginning of each block.
That really is poor.

One thing I sometimes do with C code (and sometimes C++) is to introduce an
extra { } just to be able to declare some variables where I want them. The
nice thing is that the variables also disappear when I close the {}. There's
no destructor like in C++, but at least I can't accidentally 

However, it looks like something is missing if you just do this:

    /* code here */

    {
        void* foo = malloc(size);
        /* do stuff with foo */
        free(foo);
    }

    /* more code here */

So, I define a new 'scope' keyword:

#define scope  /* use scope { } to document a nested scope */

and then code it this way:

    /* code here */

    scope
    {
        void* foo = malloc(size);
        /* do stuff with foo */
        free(foo);
    }

    /* more code here */

That way someone who reads the code doesn't wonder if I accidentally deleted
an 'if' or 'for' statement.

-Mike