Hi,
I also think that this is invalid C code. Initializers for static local 
variables have to be constant values. Variables with const modifier are 
not considered a constant value in this context (at least not by gcc, 
not sure what the standard says).

So, the following code does also NOT work...
const unsigned short a = 22;
static unsigned short b = a - 1; /* a is not seen as constant value by 
gcc */

The message "error: initializer element is not constant" is in fact a 
gcc error message stating exactly that.

If you want to use a declared constant in such case, you can write 
something like...
enum {a = 22};
static unsigned short b = a - 1; /* now a is a constant int value and 
the expression is folded to 21 */


The integer promotion you noticed is because of the used integer 
constant for arithmetics in "a - 1". Since "1" is a signed integer, "a" 
has to be promoted to a signed integer in order to compute the minus.

Cheers
Oliver


24.07.2012 07:48, Gabriel Kerneis:
> On Mon, Jul 23, 2012 at 05:45:06PM +0200, Jan Smets wrote:
>> Is this a valid coding error or a bug in cil ?
>>    static const unsigned short b = a - 1;
> This is a coding error (or at least gcc refuses to compile it).
> Not sure about the integer promotion, though.
>


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to