avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Compiler bug or Incorrect C ?


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Compiler bug or Incorrect C ?
Date: Thu, 29 Jan 2009 22:06:54 +0100 (MET)

Stu Bell <address@hidden> wrote:

> You are trying to set a global through the initializer to a variable
> value.  At *compile time*, what is the value of TIME[0]?  Unknown.

No, __TIME__[0] /is/ known at compile-time, because __TIME__ gets
replaced by a string literal by the preprocessing stage.

Pass the given code through a C++ compiler, and it will work quite
fine.

The point here is that a string literal in C is essentially an
initialized array variable.  While the user is not allowed to ever
modify that variable (so the compiler could put it into an umodifiable
location, and the compiler is allowed to share the storage for
identical string literals), syntactically it remains a variable
anyway.  C does not have a real notion of a constant, despite the
"const" keyword introduced in ISO C90.  As such, the right-hand side
of the above initializer, albeit in effect constant and known at
compile-time, does not form "constant expression" per the syntax rules
of the C language.

C++ is different in that it has real constants, and as such a string
literal there /is/ a constant, so accessing an element of that literal
in the right-hand side of the initializer of an object with static
storage is allowed.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]