F
fctk
hello,
i'm trying to compile this small program:
int main(void) {
unsigned long int max;
max = 4000000000;
return 0;
}
but i get the following warning, and can't understand why:
limits.c: In function `main':
limits.c:5: warning: this decimal constant is unsigned only in ISO C90
i read both here
(http://www-ccs.ucsd.edu/c/express.html#decimal integer constant)
and on my book (Kelley-Pohl), that if i have a decimal integer constant
with no suffix, then the compiler will choose among the following
ordered list:
1) int
2) long int
3) unsigned long int
the first one which is able to represent that constant. since on my
system both int and long int are 4 bytes sized, then i would expect
4000000000 is unsigned long int. since i am assigning an unsigned long
int constant to an unsigned long int variable, i don't see why i should
get that warning.
i know two ways to avoid the warning:
1) specifing 4000000000UL instead of 4000000000
2) using 0xEE6B2800 instead of 4000000000
but i'd like to understand why 4000000000 is not ok.
note that i'd like to write only ANSI/ISO C compatible programs
(C89/C90), no traditional C or C99 ones (after having learned C89, i
will switch to C99 if i'll have time).
i am using gcc version 3.4.4 on a gentoo linux system.
parameters: gcc -x c -ansi -pedantic -Wall -Wextra (i get that warning
also with no parameters at all)
also, i found this parameter:
-Wtraditional
[...]
* The ISO type of an integer constant has a different width or
signedness from its traditional type. This warning is only issued if
the base of the constant is ten. I.e. hexadecimal or octal values,
which typically represent bit patterns, are not warned about.
[...]
anyway, even if i put -Wno-traditional, i always get that warning.
i'm trying to compile this small program:
int main(void) {
unsigned long int max;
max = 4000000000;
return 0;
}
but i get the following warning, and can't understand why:
limits.c: In function `main':
limits.c:5: warning: this decimal constant is unsigned only in ISO C90
i read both here
(http://www-ccs.ucsd.edu/c/express.html#decimal integer constant)
and on my book (Kelley-Pohl), that if i have a decimal integer constant
with no suffix, then the compiler will choose among the following
ordered list:
1) int
2) long int
3) unsigned long int
the first one which is able to represent that constant. since on my
system both int and long int are 4 bytes sized, then i would expect
4000000000 is unsigned long int. since i am assigning an unsigned long
int constant to an unsigned long int variable, i don't see why i should
get that warning.
i know two ways to avoid the warning:
1) specifing 4000000000UL instead of 4000000000
2) using 0xEE6B2800 instead of 4000000000
but i'd like to understand why 4000000000 is not ok.
note that i'd like to write only ANSI/ISO C compatible programs
(C89/C90), no traditional C or C99 ones (after having learned C89, i
will switch to C99 if i'll have time).
i am using gcc version 3.4.4 on a gentoo linux system.
parameters: gcc -x c -ansi -pedantic -Wall -Wextra (i get that warning
also with no parameters at all)
also, i found this parameter:
-Wtraditional
[...]
* The ISO type of an integer constant has a different width or
signedness from its traditional type. This warning is only issued if
the base of the constant is ten. I.e. hexadecimal or octal values,
which typically represent bit patterns, are not warned about.
[...]
anyway, even if i put -Wno-traditional, i always get that warning.