Integer promotion and overflow

K

Keith Thompson

aegis said:
is my interpretation correct though?

for example,

long long foo = 5000000000;

if 5000000000 cannot be represented by the type int
then the compiler sees if it can be represented by type long int
and if not, then it tries long long int.

I tried this with gcc invoking -std=c99 and it seems to initialize
to the correct value but issues a warning. Should it issue
the warning? If my interpretation is correct then I do not see how this
warrants a diagnostic.

I wouldn't expect a warning in that case, but as infobahn points out
the standard allows a compiler to issue any diagnostic it likes.

You don't tell us what the warning is, so it's impossible to tell
what's going on. I tried compiling the above with several versions of
gcc. More recent versions give a warning

tmp.c:1: warning: integer constant is too large for "long" type

without "-std=c99"; none that I tried give a warning with "-std=c99".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top