bug-gnulib
[Top][All Lists]
Advanced

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

Re: regex compile warnings


From: Paul Eggert
Subject: Re: regex compile warnings
Date: Sat, 29 Jul 2006 10:46:38 -0400
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Eric Blake <address@hidden> writes:

>>> "../../lib/regexec.c", line 1412: warning: non-constant initializer: op "--"
>> 
>> I don't understand this one.  Here's the line in question:
>> 
>>   Idx num = --fs->num;
>> 
>> and I assume Idx is size_t, which is a 32-bit unsigned integer, so this
>> code should be perfectly fine C89.  Am I missing something?  It appears
>> to me to be a compiler bug.
>
> I don't have the actual C89 or C99 standards in front of me at the moment,
> but this line in the C99 draft explains it:
>
> 6.7.8 Initialization
>       [#2]  No initializer shall attempt to provide a value for an
>        object not contained within the entity being initialized.

I suspect that's talking about something different, e.g.:

  int a[10] = { [20] = 0 };

It certainly can't be talking about expressions that contain side effects,
otherwise initializations like this wouldn't be allowed:

  int c = getchar ();

> I believe it is a gcc extension that allows you to change the value of an
> unrelated variable inside an initializer.

I don't think so.  I think that code is portable K&R C code, as well
as being portable C89 and C99 code, if the item being initialized is a
scalar.

Pre-C99 did have special rules for initializing aggregate types
(initializers had to be constants), and my guess is that the compiler
is confused and is thinking that Idx is a structure.  Or maybe it
thinks Idx is 'long long' and that the 'long long' type is a
structure?  Some earlier Sun C compilers had that bug.




reply via email to

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