On 8/30/06, Nikolai Weibull <[EMAIL PROTECTED]> wrote:
On 8/30/06, Chris Littell <[EMAIL PROTECTED]> wrote:
> On 8/30/06, Nikolai Weibull <[EMAIL PROTECTED]> wrote:
> > On 8/29/06, Brad Beveridge <[EMAIL PROTECTED]> wrote:
> > > On 29/08/06, Ilya <[EMAIL PROTECTED]> wrote:
> > > > Brad Beveridge wrote:
> > > > >    static char string[2] = {0};
> > > > Should not you have "= {0, 0}" here?  Second element never get
> > > > initialized but it could be accessed by ml_append_string.
> > >
> > > That might be more clear perhaps, but when you initialize an array
> > > like that in C, the last element is propagated for the whole array.
> >
> > What C compiler are you using?  The last element is /not/ propagated
> > in C.  The rest of the array will be initialized to zero, which is the
>
> In C89 this is true.  In C99, you can initialize values out of order
> and by index range, and the final value in an array initializer is
> propogated to the rest of the values.

In C99 you can initialize values "out of order", yes, but you can't do
it with ranges.  Ranges are a GNU C extension.  The propagation
neither happens in any of the ANSI standards, nor in the GNU extended
version of C.  It's simple to test write the following in "a.c":

#include <stdio.h>

int
main(void)
{
        int is[2] = { 1 };
        int i;

        for (i = 0; i < 2; i++)
                printf("%d\n", is[i]);

        return 0;
}

And then to actually test it:

$ for std in c89 c99 gnu89 gnu99; do gcc -std=$std a.c && echo $std:
&& a.out; done
c89:
1
0
c99:
1
0
gnu89:
1
0
gnu99:
1
0

> 
http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/gcc/designated-inits.html

Nowhere in that section does it say that the last value is propagated.

Wow, I reread it and you are correct.  I'm not sure why I held that
assumption...
Also thanks for the examples.


  nikolai


Chris

Reply via email to