This is the mail archive of the gcc-bugs@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]

Re: long long int array warning


ehallick@mail.cpm.com (Erick Hallick) writes:

> Hello,
> 
> I am getting a strange warning which I believe is incorrect when declaring 
> an array of long long int's.  Consider the following simple code:
> 
> #include <stdio.h>
> 
> int main()
> {
>   int i;
>   long long int a[] =
>   {
>   1,
>   2,
>   2000000000,
>   4000000000,
>   8000000000,
>   -8000000000
>   };
> 
>   for(i=0;i<=5;i++)
>     printf("a[%d] = %lld\n", i, a[i]);
> 
> 
>   return 0;
> }
> 
> I get the following error while compiling:
> 
> ehallick@netfinity:~ > gcc -Wall test.c
> test.c: In function `main':
> test.c:11: warning: decimal constant is so large that it is unsigned

This is warning you that the constant 4000000000 is being treated as
an 'unsigned int', rather than the 'int' that it would normally be.
This would really matter if you had written -4000000000, as then
your array initialisation wouldn't do what you probably expect.

The easy fix is to write all the constants with 'll' after them, eg.

8000000000ll

-- 
- Geoffrey Keating <geoffk@cygnus.com>

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