This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc: why is "abcdef"[3] not a constant (error: initializer element is not constant)
- From: Andrew Haley <aph at redhat dot com>
- To: m-h-l <markus dot lehmann at intel dot com>, gcc-help at gcc dot gnu dot org
- Date: Mon, 11 May 2015 10:40:24 +0100
- Subject: Re: gcc: why is "abcdef"[3] not a constant (error: initializer element is not constant)
- Authentication-results: sourceware.org; auth=none
- References: <1431076943221-1146945 dot post at n5 dot nabble dot com> <554C98A4 dot 8030404 at redhat dot com> <1431086743832-1146998 dot post at n5 dot nabble dot com> <554CB581 dot 4070906 at redhat dot com> <1431092064434-1147037 dot post at n5 dot nabble dot com> <554CD3F6 dot 7000409 at redhat dot com> <554D36DA dot 8010704 at gmail dot com> <554DC060 dot 1050308 at redhat dot com> <1431331377247-1147787 dot post at n5 dot nabble dot com>
Hi,
On 05/11/2015 09:02 AM, m-h-l wrote:
> sorry, it was not my intention to complain about gcc and I never said it's a
> defect.
OK, I too am sorry for being rude. I thought your question rather
aggressive, which it clearly was not intended to be. Mea culpa. I
should not assume the worst.
> I thought this is a help forum and so I thought I can get a hint or
> trick how to work-around this. I really like gcc and you make a
> great job with it.
>
> I just did not understand the idea behind this restriction. Perhaps
> there is a good reason (beside the standard) for this.
I don't think there is. There has to be some limit on how far to do
constant propagation. This limit is necessarily arbitrary: there is
no obvious point at which to say "this far, and no further."
The need for a limit is especially true when the compiler is at -O0,
with all optimizations turned off. There have to be rules about what
expressions must be evaluated as constant expressions because we can
use a constant expression as a key in a switch statement. Is it
reasonable, then, to expect a simple C compiler always to look through
all complex expressions at compile time? Where would you stop?
The point I'm making is this: there is no one true answer. The
standard makes a cut.
Andrew.