Array intialization

Curt Wohlgemuth curtw at hpcllca.HP.COM
Tue Jun 6 07:26:36 AEST 1989


gwyn at smoke.BRL.MIL (Doug Gwyn) writes:

> In article <3420 at ihuxv.ATT.COM> bareta at ihuxv.ATT.COM (Benyukhis) writes:
> >The following declaration is illegal.  Why??????
> >char *a = "string1";
> >char *b = "string2";
> >char *c = "string3";
> >char *g[] = { a, b, c };
> 
> If the declaration has file scope, so that the variable `g' has static
> storage duration, then the problem is that initializers must be constants,
> not contents of variables.  If the declaration has block scope, then the
> problem is that run-time initialization of auto aggregates isn't supported
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> by your compiler.
  ^^^^^^^^^^^^^^^^

I fail to see how this could be a legal initialization of an auto aggregate.
The ANSI Standard says "All the expressions ... in an initializer list for
an object that has aggregate or union type shall be constant expressions.",
which, as others have pointed out, is not the case here, since 'a', 'b',
and 'c' are not constant expressions.

It matters not whether the declaration for 'g' is inside a block or not.



More information about the Comp.lang.c mailing list