On Tue, 24 Jul 2001, J . A . Magallon wrote:

> C99 is really a secure and powerfull addition. Some of this features
> are already present in some way in actual gcc or other C compilers,
> but C99 standarises them. This is what I find more usefull, extracted
> from
> http://gcc.gnu.org/gcc-3.0/c99status.html:

C99 support is better in gcc mainline (3.1). AFAIK, variable length arrays
are broken for 3.0.x.

> - restricted pointers that can not be null nor serve to walk arrays. Someone
>   can think this is stupid, but how many times did you a ptr++ that pointed
>   to a standalone struct ? It also can help to generate better code
>   (http://www.lysator.liu.se/c/restrict.html)

Or see in 6.7.3.1 in the Standard. Basically, if you have two restricted
pointers a and b, you tell the compiler that a won't reference the object
pointed by b, and vice versa. memcpy() for example shall now be declared
as:

void *memcpy(void * restrict dest, const void * restrict src, size_t n);

> - mix of code and declarations: thay are no more forced to be at the beginning
>   of a block (this also implies changes in the calling conventions, stack for
>   local variables is not reserved and initialized at once, but for each variable or
>   group of contiguous variables).

But in some cases, the rationale in C99 differs with the one for C++. I am
thinking about some weird code and declarations with labels. I don't have
an example on top of my head but I seem to remember having seen that in
the C99 rationale (n897).

> - This helps for loop and data locality (block scopes):
>   for (int i=0; ...)
>   case (char c=getchar())
>   {
>   }

Even if you replace case with a switch, that won't work. I believe the
following to be valid in C++ but not in C99

        while (T t = x) <statement>

which is equivalent to

        label:
        {
                T t = x;
                if (t) {
                        <statement>
                        goto label;
                }
        }

> - the above also makes possible non-constant length arrays (forget 50% of your
>   mallocs and allocas):
>         int a = 2;
>         double b[a];
>       double c[argc];

That doesn't work for file scope arrays for example but I am sure you
meant it implicitly ;-)

[6.7.5.2, #2]

       [#2] Only ordinary identifiers (as defined  in  6.2.3)  with
       both  block scope or function prototype scope and no linkage
       shall have a variably modified type.  If  an  identifier  is
       declared  to  be  an object with static storage duration, it
       shall not have a variable length array type.

> - designated initializers
>   struct complex { double a,b } = { b:7, a:3 ];

That doesn't work like that, this is a GCC notation I think.

struct a_struct { double a, b; } x = { .b = 3.0, .a = 2.0 };
[You can initialize the struct in whatever order you want]

int my_array[10] = { 0, 1, 2, [8] = 7 };


Reply via email to