Re: Describing a tree



Ian Collins <ian-news@xxxxxxxxxxx> writes:

On 07/22/10 01:00 AM, Ben Bacarisse wrote:
Nick Keighley<nick_keighley_nospam@xxxxxxxxxxx> writes:
On 21 July, 09:16, Ian Collins<ian-n...@xxxxxxxxxxx> 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.
.



Relevant Pages

  • Re: calling an ada procedure from C++
    ... >> Standard C does not permit returning structures on the stack IIRC. ... > But you must make sure that the C and Ada compilers ... It fills in this static area with the return value, ...
    (comp.lang.ada)
  • Re: Operator Precence Issue/Question
    ... the bottom two bits of P8 were set, ... There is a mistake in this code in that equality is higher precedence ... Some compilers and some "lint" programs will issue ... compiler, (since as you say, it's perfectly valid C). ...
    (comp.lang.c)
  • Re: Operator Precence Issue/Question
    ... semantic error on his part, not that the code was rejected by the ... compiler, (since as you say, it's perfectly valid C). ... and I'm also saying that some compilers will issue ... warnings for "perfectly valid but quite possibly erroneous C." ...
    (comp.lang.c)
  • Re: Describing a tree
    ... Tree yggdrasil[] = ... code which goes against what most people would call perfectly valid C. ... tree.c:27: warning: initializer element is not computable at load time ... Both C99 compilers I tried are happy with the code, ...
    (comp.lang.c)
  • Re: [OT] Compiler and OS considerations
    ... Microsoft compilers understand the '-o' in *that* situation and permit ... you to control the name of the executable in that way. ...
    (comp.lang.perl.modules)