Should GCC warn when __LINE__ is treated as %u %d %i?

Segher Boessenkool segher@kernel.crashing.org
Sun Feb 17 14:47:00 GMT 2019


Hi!

On Sun, Feb 17, 2019 at 02:12:54PM +0000, Jonny Grant wrote:
> 1) should this not give type conversion warnings?
> 
> printf("lineoutput %d:%u:%i\n", __LINE__, __LINE__, __LINE__);

This is explicitly allowed in (C11) 7.16.1.1/2:

"one type is a signed integer type, the other type is the corresponding
unsigned integer type, and the value is representable in both types".

> 2) Should __LINE__ expand as an 'int', or 'unsigned int'?

It should expand as an integer constant.

> Had expected line 9 to expand as '9U', but -save-temps shows it ends up as:
> 
> printf("lineoutput %d:%u:%i\n", 9, 9, 9);

So in GCC it will apparently be a signed int usually, except maybe if you
have >2G lines, then it becomes unsigned (if int is 32 bits), or >4G when
is will become long or long long.  See 6.4.4.1/5 for what type an integer
constant is.


Segher



More information about the Gcc-help mailing list