Ian Collins <ian-> writes:
> On 07/22/10 01:00 AM, Ben Bacarisse wrote:
>> Nick Keighley<> writes:
>>> On 21 July, 09:16, Ian Collins<ian-n...@hotmail.com> wrote:
>>>> On 07/21/10 07:17 PM, Nick Keighley wrote:
>>>>
>>>>>>> int main (void)
>>>>>>> {
>>>>>>> Tree yggdrasil[] =
>>>>>>> {
>>>>>>> {"red",&yggdrasil[1],&yggdrasil[2]},
>>>>>>> {"blue",&yggdrasil[3],&yggdrasil[4]},
>>>>>>> {"black", 0, 0},
>>>>>>> {"yellow", 0, 0},
>>>>>>> {"green", 0, 0}
>>>>>>> };
>>>>
>>>>
>>>> It's perfectly valid C.
>>
>> I'd say that it is not. An implementation is permitted to reject the
>> code which goes against what most people would call perfectly valid C.
>>
>>> ah yes, even with pedantic I only got
>>>
>>> D:\bin\net>gcc -W -Wall -pedantic -ansi tree.c
>>> tree.c: In function `main':
>>> tree.c:27: warning: initializer element is not computable at load time
>>> [several times]
>>
>> That does not tell you if it is or is not valid C!
>
> If you compile for the correct version of C, it is.
Sorry, I don't follow you. All I am saying is that a warning from gcc
does not tell you if the code is valid.
The error is not a constraint violation so a compiler need not say a
word about it. Had gcc been silent on the matter you could not conclude
that the code is fine. Equally, gcc is permitted to warn about anything
it likes, so a warning does not mean that the code is not valid.
>> The standard says that when an address constant references an object it
>> much be a static object. I.e. a conforming C implementation can reject
>> (but, as it happens, need not reject) the program. Is that "perfectly
>> valid C"? I'd say not, although it is OK in the sense that an
>> implementation may permit other forms of constant expression so there is
>> no reason that it should not be accepted. If you use that sort of
>> construct your code won't always compile on other systems.
>
> Both C99 compilers I tried are happy with the code, C89 compilers
> complained.
I still don't get your point. It's good that the C89 compilers
complained but what do you mean by pointing out that the C99 ones are
happy with it? Does that lead you to believe that there is no problem
with the construct?
No C99 compiler need diagnose the error (well, lets's call it an
extension rather than an error) so the fact that they seem happy does
not tell you much about the validity of the construct.
--
Ben.
|