473,854 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

big decimal integer constant warning

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.ht...ger%20constant)
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.
Mar 29 '06 #1
6 35680


fctk wrote On 03/29/06 10:26,:
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


The compiler is warning you that the rules changed
between C90 and C99, and that the type of the constant
depends on which Standard you follow -- to put it another
way, the type of the constant is "unstable" in the sense
that it could change with a compiler upgrade.

For C90, the rule is as you stated: the type will be
the first of int, long int, or unsigned long int that
can accommodate the value, and on your system this comes
down to unsigned long int.

For C99, the type will be the first of int, long int,
or long long int that can accommodate the value, which
for your system would turn out to be long long int.

Recommendation: If you want an unsigned long, tack
on a "UL" suffix.

--
Er*********@sun .com

Mar 29 '06 #2
On Wed, 29 Mar 2006 17:26:08 +0200, fctk <-> wrote in comp.lang.c:
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
That's because the rules changed in 1999.
i read both here
(http://www-ccs.ucsd.edu/c/express.ht...ger%20constant)
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.
That's because the rules changed in 1999. If your compiler uses the
C99 rules, an unadorned decimal constant is the first one of:

-- signed int
-- signed long
-- signed long long

....in which it fits. Under C99, an unadorned decimal constant never
becomes an unsigned type.

So the diagnostic is telling you that the constant is interpreted
differently depending on which version of ISO C is being conformed to.
If the compiler is invoked in C90 conforming mode, the type of the
constant is "unsigned long", but in C99 conforming mode, the type is
"signed long long". If the destination was a signed type, the actual
value after initialization might be different between the two
versions. And this code could break on other platforms.
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.
Nobody says that it isn't "OK". A compiler is allowed to issue a
diagnostic about anything for any reason, as long as it issues those
required by the standard.
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).
Then follow the MISRA rule (one of the good ones) about always
specifying a type for numeric literals.
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)
IIRC, 3.x versions of gcc had some C99 features included, and they,
and even earlier versions, of gcc supported the "long long" int types
as an extension to C90.
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.


The real answer is "don't do this". Specify the exact type of your
literal with a suffix, for maximum portability under any version of
the C standard.

Also consult your compiler documentation. There is some way to tell
gcc which version of the C standard you want it to conform to.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 29 '06 #3
On 2006-03-29 10:26:08 -0500, fctk <-> said:
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


Because under C99, the type of the constant is "long long" (which is signed),
while under C90 (assuming 4 byte ints and longs), it is "unsigned long" (which
is unsigned). Hence, the warning is telling you that your constant is unsigned
under C90, but not under C99, and that you may get different results when you
change compilers.

--
Clark S. Cox, III
cl*******@gmail .com

Mar 29 '06 #4
Jack Klein wrote:
Also consult your compiler documentation. There is some way to tell
gcc which version of the C standard you want it to conform to.


http://gcc.gnu.org/onlinedocs/gcc-3....t-Options.html

-std=c89 (same as -ansi)
-std=c99
Mar 30 '06 #5
Eric Sosman wrote:
The compiler is warning you that the rules changed
between C90 and C99, and that the type of the constant
depends on which Standard you follow -- to put it another
way, the type of the constant is "unstable" in the sense
that it could change with a compiler upgrade.
Jack Klein wrote: That's because the rules changed in 1999.
Clark S. Cox III wrote: Because under C99, the type of the constant is "long long" (which is signed),
while under C90 (assuming 4 byte ints and longs), it is "unsigned long" (which
is unsigned). Hence, the warning is telling you that your constant is unsigned
under C90, but not under C99, and that you may get different results when you
change compilers.


ok, it seems you all agree on the reason of that warning.

i tried to specify -std=iso9899:199 0 (C89/C90) in the gcc parameters
list, but i get that warning again.

i still wonder. i don't mind about C99, i'd like gcc not to be aware of
its existence. when C89/C90 was made (1989/1990) C99 didn't existed, so
why telling me my program can produce different results if compiled with
C99 standard? C99 doesn't exist...

i hope it's clear what i mean...
Apr 1 '06 #6
fctk schrieb:
Eric Sosman wrote:
The compiler is warning you that the rules changed
between C90 and C99, and that the type of the constant
depends on which Standard you follow -- to put it another
way, the type of the constant is "unstable" in the sense
that it could change with a compiler upgrade.

Jack Klein wrote:
That's because the rules changed in 1999.

Clark S. Cox III wrote:
Because under C99, the type of the constant is "long long" (which is
signed),
while under C90 (assuming 4 byte ints and longs), it is "unsigned
long" (which
is unsigned). Hence, the warning is telling you that your constant is
unsigned
under C90, but not under C99, and that you may get different results
when you
change compilers.


ok, it seems you all agree on the reason of that warning.

i tried to specify -std=iso9899:199 0 (C89/C90) in the gcc parameters
list, but i get that warning again.

i still wonder. i don't mind about C99, i'd like gcc not to be aware of
its existence. when C89/C90 was made (1989/1990) C99 didn't existed, so
why telling me my program can produce different results if compiled with
C99 standard? C99 doesn't exist...

i hope it's clear what i mean...


Yes.
This is rather a request to the compiler to not warn you about
problems other people might have on other compilers when
compiling your code.

Note that, in principle, a compiler can warn you about everything
it likes to ("Your code contains 42 'i's -- that is a bad omen on
days like this one").
Maybe, in gnu.gcc.help someone can tell you how to achieve that
(or maybe you find something in the gcc documentation yourself).

However, if you go this way, then consider at least protecting
these others (or maybe even yourself) from errors:
#if __STDC_VERSION_ _ >= 199901L
# error My code does not work for C99 or newer standards
#endif

If you are maintaining old code and if this warning comes up at
hundreds of different places, switching off or filtering this
warning and putting the above in one source file may be a
sensible way to go. The decision should be clearly documented
somewhere.
If you are writing new code, then the warning is justified and
removing its cause as often as it comes up is just sensible --
why leave unnecessary and potentially dangerous degrees of
freedom in your code if you can say exactly what you mean?
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Apr 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6207
by: Günter Zöchbauer | last post by:
can anyone tell why is valid but produces compiler error: An attribute argument must be a constant expression, typeof expression or array creation expression
11
1718
by: Steven T. Hatton | last post by:
I say no, 0 is _not_ a decimal literal. Anybody disagree? If you do agree with me, then what do you think it is? -- If our hypothesis is about anything and not about some one or more particular things, then our deductions constitute mathematics. Thus mathematics may be defined as the subject in which we never know what we are talking about, nor whether what we are saying is true.-Bertrand Russell
4
17890
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the problem is the charset? How I can avoid this warning? But the worst thing isn't the warning, but that the program doesn't work! The program execute all other operations well, but it don't print the converted letters: for example, in the string...
20
2384
by: Russell Shaw | last post by:
Hi, I'm using gcc-3.4.3 on a linux pc. The ints and long ints are 32 bits and long long ints are 64 bits. When i have: int num=9600; long long int reg=(long long)800000000000/(5000000*num); the denominator overflows and gives an incorrect answer: reg=1059
15
2513
by: Jordan Abel | last post by:
Say int is a 16-bit twos-complement type. Is the expression (-32768) actually negative? Or is it the unsigned int literal 32768 with the unary minus operator applied to it, resulting in the value of the expression being an unsigned int 32768, which can then trap when being assigned to a signed int type
17
1876
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code: ============================ #include <stdio.h> void fcn (char *str)
10
4976
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
25
3054
by: Lennart Benschop | last post by:
Python has had the Decimal data type for some time now. The Decimal data type is ideal for financial calculations. Using this data type would be more intuitive to computer novices than float as its rounding behaviour matches more closely what humans expect. More to the point: 0.1 and 0.01 are exact in Decimal and not exact in float. Unfortunately it is not very easy to access the Decimal data type. To obtain the decimal number 12.34 one...
26
3722
by: kerravon | last post by:
The following C program: int main(void) { int x = -2147483648; return (0); } Produces the following warning:
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10749
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9512
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7912
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4152
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.