V
Vivek Mohan
Hi,
I am using gcc, and I am a bit confused about the warning message I
got when I compiled and ran this small code snippet -
int main() {
unsigned long x = 3*1024*1024*1024; /* 3GB */
printf(" %x ", x);
}
I got the following error,
In function `main':
:4: warning: integer overflow in expression
but when I use this
int main() {
unsigned long x = 0xC0000000; /* 3GB */
printf(" %x ", x);
}
It doesn't give out any errors. Any idea as to why its warning about
integer overflow when it is well within the range of 32bits ? My gcc
-v
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.3.3 [FreeBSD] 20031106
Vivek
I am using gcc, and I am a bit confused about the warning message I
got when I compiled and ran this small code snippet -
int main() {
unsigned long x = 3*1024*1024*1024; /* 3GB */
printf(" %x ", x);
}
I got the following error,
In function `main':
:4: warning: integer overflow in expression
but when I use this
int main() {
unsigned long x = 0xC0000000; /* 3GB */
printf(" %x ", x);
}
It doesn't give out any errors. Any idea as to why its warning about
integer overflow when it is well within the range of 32bits ? My gcc
-v
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.3.3 [FreeBSD] 20031106
Vivek