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 12:54:18 -0700 Organization: None to speak of Lines: 31 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="U2FsdGVkX19WVgLxjrozwpHQfvykwSnY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:QQ+WMLYiIQ4hj38228sck8mAOMM= sha1:EB8ovPXFw7juWKTTJeZQZJx9Vkk= Xref: csiph.com comp.lang.c:109625 supercat@casperkitty.com writes: > On Tuesday, May 9, 2017 at 1:57:22 PM UTC-5, Keith Thompson wrote: >> On the other hand, given: >> >> char foo[] = "hello"; >> char *bar = foo; >> >> the expression `foo` in the initializer yields the address of a >> static object, not the (current) value of that object. The compiler >> has to be able to generate code that refers to the address of a >> static object anyway, so there's no extra burden in requiring it >> to treat such an address as a compile-time constant expression. > > Actually, in some cases the latter may be a significant burden, but it is > one that the authors of the C Standard thought was worthwhile to impose. > Most notably, there are some platforms where static variables are accessed > using a displacement from an address register. Such a design makes it > practical for a system without a memory-management unit (e.g. the classic > Macintosh) to have multiple applications in memory simultaneously but means > that after a program is loaded into memory as a blob, the startup code will > need to patch all static objects that are initialized to hold addresses of > functions or other static objects. I said it's no *extra* burden. It's a burden that's required for handling static objects at all. -- 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"