This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Warnings on long constants in gcc 3.3, 3.4


Hi all - 

I've started seeing warnings from gcc of this sort:

test.c:7: warning: integer constant is too large for "long" type

for things like this:

#define LONGLONGMACRO 1099511628211
printf("%lld\n", LONGLONGMACRO);

(it's the printf line that generates the warning; this is coming from
gcc, not cpp).

gcc 3.2.2 did not warn, but 3.3.3 and 3.4.0 both do.  (These are all Red
Hat Linux / Fedora Core packages, on an intel ia32 box).

While I could append "LL" to the constant (with apparently some
portability problems for the MSVC compiler, argh), it has been stated to
me that c99 should promote the type of the constant to something that it
will fit into.

My 2nd edition K&R says

        The type of an integer depends on its form, value, and suffix...
        If it is unsuffixed and decimal, it has the first of these types
        in which it can be represented: int, long int, unsigned long
        int.

and the C99 standard apparently says something similar in 6.4.4.1,
incorporating long long as well (from what I can gather).

So I'm curious; should this warning be there, or should gcc be silently
promoting it to a larger type?

Thanks,

-Eric

-- 
Eric Sandeen      XFS for Linux   http://oss.sgi.com/projects/xfs
sandeen@sgi.com   SGI, Inc.          651-683-3102


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]