This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: STRING_COMMA_LEN
On Wed, 24 Oct 2007, Andreas Schwab wrote:
> Daniel Jacobowitz <drow@false.org> writes:
>
> > We got a report (gdb/2339) that GDB 6.7 doesn't build with the Sun
> > compiler.
> >
> > "elf.c", line 856: non-constant initializer: op "?"
> > "elf.c", line 859: non-constant initializer: op "?"
> > "elf.c", line 864: non-constant initializer: op "?"
> > "elf.c", line 871: non-constant initializer: op "?"
> >
> > That's a STRING_COMMA_LEN:
> >
> > #define STRING_COMMA_LEN(STR) (STR), ((STR) ? sizeof (STR) - 1 : 0)
> >
> > I don't know if this is pedantically correct C or not; just
> > passing it along...
>
> The compiler is broken, conditional expressions are explicitly allowed
> in constant expressions. Of course, I don't know if the Sun compiler
> claims standards conformance in any way...
The problem with that would seem to be to be the use of the string
literal, not the conditional expression as the Sun compiler claims. The
possibilities in initializers are:
- an arithmetic constant expression
- a null pointer constant
- an address constant
- an address constant for an object type plus or minus an integer
constant expression
It's not the first, since string constants aren't in the list of things
allowed in arithmetic constant expressions. It's not a null pointer
constant. And it's not an address constant (plus or minus) since it's not
of pointer type.
--
Joseph S. Myers
joseph@codesourcery.com