public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* compiler warning about literal
@ 2014-11-17 16:22 Luchezar Belev
  2014-11-17 16:45 ` Luchezar Belev
  2014-11-17 16:46 ` Jonathan Wakely
  0 siblings, 2 replies; 6+ messages in thread
From: Luchezar Belev @ 2014-11-17 16:22 UTC (permalink / raw)
  To: gcc-help

hi,

when i try to compile this c code:
long long t = 2684354560;
gcc (version 4.8.2) says: " ...warning: this decimal constant is
unsigned only in ISO C90 [enabled by default]"

i added the option -std=C90 but i still get the same warning.
Is there a way one can get rid of this warning (other than adding the
"u" suffix to the literal, which i can't do for complicated reasons
that are beyond this question)

I wonder why does gcc give such warning at all given that in either
standard the literal decimal number  "2684354560" is valid:
 a) in ISO C90 it will be interpreted as unsigned long and
 b) in ISO C99 it will be interpreted as signed long long

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: compiler warning about literal
  2014-11-17 16:22 compiler warning about literal Luchezar Belev
@ 2014-11-17 16:45 ` Luchezar Belev
  2014-11-17 16:50   ` Nicholas Mc Guire
  2014-11-17 16:46 ` Jonathan Wakely
  1 sibling, 1 reply; 6+ messages in thread
From: Luchezar Belev @ 2014-11-17 16:45 UTC (permalink / raw)
  To: gcc-help

note the following strange gcc behavior:

 "long long t = 268435456;" =>doesn't give warning
 "long long t = 2684354560;" => gives warning!
 "long long t = 26843545600;" => doesn't give warning!

it looks to me that there is something wrong here

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: compiler warning about literal
  2014-11-17 16:22 compiler warning about literal Luchezar Belev
  2014-11-17 16:45 ` Luchezar Belev
@ 2014-11-17 16:46 ` Jonathan Wakely
  1 sibling, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2014-11-17 16:46 UTC (permalink / raw)
  To: Luchezar Belev; +Cc: gcc-help

On 17 November 2014 16:22, Luchezar Belev <lukcho@gmail.com> wrote:
> hi,
>
> when i try to compile this c code:
> long long t = 2684354560;
> gcc (version 4.8.2) says: " ...warning: this decimal constant is
> unsigned only in ISO C90 [enabled by default]"
>
> i added the option -std=C90 but i still get the same warning.
> Is there a way one can get rid of this warning (other than adding the
> "u" suffix to the literal, which i can't do for complicated reasons
> that are beyond this question)

The right thing to do is use an ll suffix.

long long t = 2684354560ll;



> I wonder why does gcc give such warning at all given that in either
> standard the literal decimal number  "2684354560" is valid:
>  a) in ISO C90 it will be interpreted as unsigned long and
>  b) in ISO C99 it will be interpreted as signed long long

The fact it means different things in different cases is why you get a warning.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: compiler warning about literal
  2014-11-17 16:45 ` Luchezar Belev
@ 2014-11-17 16:50   ` Nicholas Mc Guire
       [not found]     ` <CAJtzQrzHnh_=_UZ=-y=HZEBVQYgWFzGVzvUTLG6U_HVtxObfhQ@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Nicholas Mc Guire @ 2014-11-17 16:50 UTC (permalink / raw)
  To: Luchezar Belev; +Cc: gcc-help

On Mon, 17 Nov 2014, Luchezar Belev wrote:

> note the following strange gcc behavior:
> 
>  "long long t = 268435456;" =>doesn't give warning
>  "long long t = 2684354560;" => gives warning!
>  "long long t = 26843545600;" => doesn't give warning!
> 
> it looks to me that there is something wrong here

I think thats correct

268435456 fit and was positive 
2684354560 is a negative long on the right side and was sign extended -> warning
26843545600 is a long long I guess and thus again positive -> no warning

thx!
hofrat

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: compiler warning about literal
       [not found]         ` <20141117171418.GA30462@opentech.at>
@ 2014-11-17 17:28           ` Luchezar Belev
  2014-11-17 17:34             ` Luchezar Belev
  0 siblings, 1 reply; 6+ messages in thread
From: Luchezar Belev @ 2014-11-17 17:28 UTC (permalink / raw)
  To: gcc-help

I think i got it why GCC gives the warning with -std=C90.
It basically wants to say:
"Now that we are under the C90 rules, this literal is 'unsigned long',
but under some newer standard it sould be 'signed long long', so make
sure your code won't broke if you try to compile it under new
standard".

Now the only question that remains is: why there is no way to disable
the warning?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: compiler warning about literal
  2014-11-17 17:28           ` Luchezar Belev
@ 2014-11-17 17:34             ` Luchezar Belev
  0 siblings, 0 replies; 6+ messages in thread
From: Luchezar Belev @ 2014-11-17 17:34 UTC (permalink / raw)
  To: gcc-help

The reason i can't use suffixes is because the real code that bothers
me is a large automatically generated array of unsigned decimal
numbers (all are less than 2^32) and it isn't practical to edit them
by hand.
Also I can't easily change the tool that generates them to make it
place suffixes.

On Mon, Nov 17, 2014 at 7:28 PM, Luchezar Belev <lukcho@gmail.com> wrote:
> I think i got it why GCC gives the warning with -std=C90.
> It basically wants to say:
> "Now that we are under the C90 rules, this literal is 'unsigned long',
> but under some newer standard it sould be 'signed long long', so make
> sure your code won't broke if you try to compile it under new
> standard".
>
> Now the only question that remains is: why there is no way to disable
> the warning?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-17 17:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-17 16:22 compiler warning about literal Luchezar Belev
2014-11-17 16:45 ` Luchezar Belev
2014-11-17 16:50   ` Nicholas Mc Guire
     [not found]     ` <CAJtzQrzHnh_=_UZ=-y=HZEBVQYgWFzGVzvUTLG6U_HVtxObfhQ@mail.gmail.com>
     [not found]       ` <20141117170828.GA27808@opentech.at>
     [not found]         ` <20141117171418.GA30462@opentech.at>
2014-11-17 17:28           ` Luchezar Belev
2014-11-17 17:34             ` Luchezar Belev
2014-11-17 16:46 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).