Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: error: initializer element is not constant| Date: Tue, 09 May 2017 11:41:25 -0700 Organization: None to speak of Lines: 41 Message-ID: References: <37hQA.7825$Aj7.1467@fx33.am4> <3dv3hc1ueu2en2hl1oprs3ui6j6bdoqmf1@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="760eeae9966e2029c529e2d23bf0143c"; logging-data="18255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+G4zm5npvmJ83WAj/RyLFk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ecO39C/XSoyfV/fBS+KvSGwS9s0= sha1:YBEkGsNlt/HMOTsEKg0x0ys4M3g= Xref: csiph.com comp.lang.c:109614 Barry Schwarz writes: > On Tue, 9 May 2017 19:20:41 +0200, jak wrote: [...] >>Ok. Then return to the first question. What information is missing from >>the compiler to solve this? >> >>char *Date = "01-01-80"; >>char *Phrase[] = >>{ >> NULL, /*1*/ >> Date, /*2*/ >> NULL, /*3*/ >> NULL /*4*/ >>}; >> >>...and why does it solve this? >> >>char *DescDate = "Date: "; >>char *Date = "01-01-80"; >>char *CrLf = "\r\n"; >>char *Text = "Dear friend..."; >> >>char **Phrase[] = >>{ >> &DescDate, &Date, &CrLf, >> &Text, &CrLf >>}; > > Possibly because the address of a static variable is a compile time > const (note const, not constant) while the value of a static variable > is not. You got that backwards. The address of a static variable is a compile time *constant*. Specifically, it's an *address constant* as defined in N1570 6.6p9. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"