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

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

 





On 17/02/2019 14:47, Segher Boessenkool wrote:
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

Thank you for your reply.
Regards, Jonny




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux