public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* long long constant
@ 2004-06-17 22:40 Vincent Torri
  2004-06-18 12:08 ` Eljay Love-Jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Torri @ 2004-06-17 22:40 UTC (permalink / raw)
  To: gcc-help


Hello

i have experienced weird behavior with the initialization of a constant : 

static long long const rounder = 0x0000400000004000;

on gcc 2.96, no error or warning
on gcc 3.3.1 or 3.3.2 or 3.3.4 there's a warning or an error

If i change the initialization above by
static long long const rounder = 0x0000400000004000LL;

it works

could someone explain me why ? 

espacially, is there some known problems with initializing lonng constants
with gcc 3.3.x ?

Thank you

Vincent TORRI


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

* Re: long long constant
  2004-06-17 22:40 long long constant Vincent Torri
@ 2004-06-18 12:08 ` Eljay Love-Jensen
  2004-06-18 12:32   ` Falk Hueffner
  0 siblings, 1 reply; 5+ messages in thread
From: Eljay Love-Jensen @ 2004-06-18 12:08 UTC (permalink / raw)
  To: Vincent Torri, gcc-help

Hi Vincent,

Both long long, and long long numeric literals, are extensions.

A long long numeric literal requires the LL suffix.  The compiler doesn't 
automagically promote "too big" numeric literals into long longs.

My recommendation is to rely upon the 5 year old C99 header file <stdint.h> 
(even in C++), and use their facilities.

#include <stdint.h>
static int64_t const rounder = INT64_C(0x0000400000004000);

HTH,
--Eljay

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

* Re: long long constant
  2004-06-18 12:08 ` Eljay Love-Jensen
@ 2004-06-18 12:32   ` Falk Hueffner
  2004-06-18 13:08     ` Eljay Love-Jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Falk Hueffner @ 2004-06-18 12:32 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: Vincent Torri, gcc-help

Eljay Love-Jensen <eljay@adobe.com> writes:

> A long long numeric literal requires the LL suffix.  The compiler
> doesn't automagically promote "too big" numeric literals into long
> longs.

Actually it does if you tell it to follow the current standard C99
with -std=c99 (the default is gnu89).

-- 
	Falk

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

* Re: long long constant
  2004-06-18 12:32   ` Falk Hueffner
@ 2004-06-18 13:08     ` Eljay Love-Jensen
  2004-06-18 20:48       ` Vincent Torri
  0 siblings, 1 reply; 5+ messages in thread
From: Eljay Love-Jensen @ 2004-06-18 13:08 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: Vincent Torri, gcc-help

I stand corrected for C99!  :-)

(I use C from 1985 to 1990.  After I switched to C++ in 1990, I've not gone 
back to C.)

Not true for C++98.

$ g++ -std=c99 -c longlong.cpp
cc1plus: warning: "-std=c99" is valid for C/ObjC but not for C++
longlong.cpp:1: error: integer constant is too large for "long" type

--Eljay

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

* Re: long long constant
  2004-06-18 13:08     ` Eljay Love-Jensen
@ 2004-06-18 20:48       ` Vincent Torri
  0 siblings, 0 replies; 5+ messages in thread
From: Vincent Torri @ 2004-06-18 20:48 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: Falk Hueffner, gcc-help


Thank you for your answers 

Vincent TORRI

On Fri, 18 Jun 2004, Eljay Love-Jensen wrote:

> I stand corrected for C99!  :-)
> 
> (I use C from 1985 to 1990.  After I switched to C++ in 1990, I've not gone 
> back to C.)
> 
> Not true for C++98.
> 
> $ g++ -std=c99 -c longlong.cpp
> cc1plus: warning: "-std=c99" is valid for C/ObjC but not for C++
> longlong.cpp:1: error: integer constant is too large for "long" type
> 
> --Eljay
> 
> 

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

end of thread, other threads:[~2004-06-18 20:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-17 22:40 long long constant Vincent Torri
2004-06-18 12:08 ` Eljay Love-Jensen
2004-06-18 12:32   ` Falk Hueffner
2004-06-18 13:08     ` Eljay Love-Jensen
2004-06-18 20:48       ` Vincent Torri

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).