Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!motcsd!hpda!hpcuhb!hpcllla!hpcllca!curtw From: curtw@hpcllca.HP.COM (Curt Wohlgemuth) Newsgroups: comp.lang.c Subject: Re: Array intialization Message-ID: <7330014@hpcllca.HP.COM> Date: 5 Jun 89 21:26:36 GMT References: <3420@ihuxv.ATT.COM> Organization: Hewlett Packard Calif. Language Lab Lines: 24 gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > In article <3420@ihuxv.ATT.COM> bareta@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.