public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17499] New: long long constant broken
@ 2004-09-15 10:55 L dot Gregory at Surrey dot ac dot uk
2004-09-17 18:09 ` [Bug c++/17499] " pyrodave at msn dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: L dot Gregory at Surrey dot ac dot uk @ 2004-09-15 10:55 UTC (permalink / raw)
To: gcc-bugs
It seems that long long constants may be broken in gcc-3.3.4.
The following code fragment demonstrates the problem.
#include <stdint.h>
#include <iostream>
#include <stdio.h>
#include <stdint.h>
using namespace std ;
int main (void)
{
unsigned long long int tmp = 0x0008000000000000ULL;
cout << "\n value is " << hex << tmp << endl ;
}
This code is compiled simply with g++ tester.cc
gcc-3.3.4 gives the following warning:-
"integer constant is too large for its type".
and gives "value is 0" as its output.
gcc-3.3.3 gives no such warning and gives :
" value is 8000000000000" as its answer.
Forgive me If this is not a bug and an oversight on my part.
--
Summary: long long constant broken
Product: gcc
Version: 3.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: L dot Gregory at Surrey dot ac dot uk
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
@ 2004-09-17 18:09 ` pyrodave at msn dot com
2004-09-17 18:53 ` wilson at specifixinc dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pyrodave at msn dot com @ 2004-09-17 18:09 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pyrodave at msn dot com 2004-09-17 18:09 -------
> gcc-3.3.4 gives the following warning:-
> "integer constant is too large for its type".
> and gives "value is 0" as its output.
>
> gcc-3.3.3 gives no such warning and gives :
> " value is 8000000000000" as its answer.
I just found this bug report while researching a problem I was having.
using gcc-3.2.2 the following code:
#include <stdio.h>
typedef unsigned long long USB64;
unsigned long long zz;
int main()
{
zz = 10293847561029384756;
char aa[20];
sprintf(aa , "%20.20d" , zz);
printf("%s\n",aa);
}
generated the warning "Decimal constant is so large it is unsigned" and
compiled, but when ran, the result is 00000000001328380468.
When I changed it to add the ULL at the end of the constant, the warning
disappeared but the result was the same.
I just installed gcc-3.3.4-20040914 and got exactly the same results.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
2004-09-17 18:09 ` [Bug c++/17499] " pyrodave at msn dot com
@ 2004-09-17 18:53 ` wilson at specifixinc dot com
2004-09-17 18:55 ` pyrodave at msn dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: wilson at specifixinc dot com @ 2004-09-17 18:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From wilson at specifixinc dot com 2004-09-17 18:53 -------
Subject: Re: long long constant broken
pyrodave at msn dot com wrote:
> ------- Additional Comments From pyrodave at msn dot com 2004-09-17 18:09 -------
> zz = 10293847561029384756;
> char aa[20];
> sprintf(aa , "%20.20d" , zz);
This doesn't seem to have anything to do with the original bug report,
which is a C++ issue.
Constants have type "int", unless you use an extension. If a constant
is too big for an int, it will be truncated. Thus you must use the ULL
extension to get the behaviour you want.
%d prints an "int". If you want to print a long, you must use %ld. If
you want to print a long long, you must use %lld. This is according to
the ISO C99 standard. Since this is a relatively recent standard, your
C library may not support it, and/or may have it own different
extensions for long long. This isn't a gcc issue, and gcc does not
contain a C library. See the docs for your C library.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
2004-09-17 18:09 ` [Bug c++/17499] " pyrodave at msn dot com
2004-09-17 18:53 ` wilson at specifixinc dot com
@ 2004-09-17 18:55 ` pyrodave at msn dot com
2004-09-17 19:59 ` pyrodave at msn dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pyrodave at msn dot com @ 2004-09-17 18:55 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pyrodave at msn dot com 2004-09-17 18:55 -------
same results with these typedefs found in stdint.h:
typedef unsigned long long uint64_t;
typedef unsigned long long uint_least64_t;
typedef unsigned long long uint_fast64_t;
Aslo when incremented from ULONG_MAX the value flips as if it was a signed long.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
` (2 preceding siblings ...)
2004-09-17 18:55 ` pyrodave at msn dot com
@ 2004-09-17 19:59 ` pyrodave at msn dot com
2004-09-17 20:16 ` schwab at suse dot de
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pyrodave at msn dot com @ 2004-09-17 19:59 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pyrodave at msn dot com 2004-09-17 19:58 -------
> %d prints an "int". If you want to print a long, you must use %ld. If
> you want to print a long long, you must use %lld. This is according to
> the ISO C99 standard. Since this is a relatively recent standard, your
> C library may not support it, and/or may have it own different
> extensions for long long. This isn't a gcc issue, and gcc does not
> contain a C library. See the docs for your C library.
I am such an ameteur, and whats worse, I knew better....You are absolutely
correct... In my frustration I was intermingling C and C++ and went totally
braindead on stdio crap.(Good thing I don't program for a living...)
Although I thought
18446744073709551615 was the ULLONG_MAX....Why is
10293847561029384756 returning a negative value (-08152896512680166860)? No
biggie, I'm not looking for an answer to that here. Please forgive my ignorance.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
` (3 preceding siblings ...)
2004-09-17 19:59 ` pyrodave at msn dot com
@ 2004-09-17 20:16 ` schwab at suse dot de
2004-09-17 20:19 ` pyrodave at msn dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: schwab at suse dot de @ 2004-09-17 20:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From schwab at suse dot de 2004-09-17 20:16 -------
> Constants have type "int", unless you use an extension. If a constant
> is too big for an int, it will be truncated.
This is wrong. Integer constants basically have the smallest type they fit
in. But 10293847561029384756 is even too big for long long, so its type is
unsigned long long, hence the warning. (The standard makes this actually
undefined.)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
` (4 preceding siblings ...)
2004-09-17 20:16 ` schwab at suse dot de
@ 2004-09-17 20:19 ` pyrodave at msn dot com
2004-09-18 5:02 ` pinskia at gcc dot gnu dot org
2004-09-24 13:10 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: pyrodave at msn dot com @ 2004-09-17 20:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pyrodave at msn dot com 2004-09-17 20:19 -------
as I said, I am such an amateur (%u)
On a lighter not, the originator's code works fine under 3.3.4-20040914 on RH9
x86-32 system... Don't worry, this is the last little bit of space I'll be
wasting here for a good long while. (Like until I go to college)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
` (5 preceding siblings ...)
2004-09-17 20:19 ` pyrodave at msn dot com
@ 2004-09-18 5:02 ` pinskia at gcc dot gnu dot org
2004-09-24 13:10 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-18 5:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-09-18 05:02 -------
Hmm, this works for me.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17499] long long constant broken
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
` (6 preceding siblings ...)
2004-09-18 5:02 ` pinskia at gcc dot gnu dot org
@ 2004-09-24 13:10 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-24 13:10 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-09-24 13:10 -------
This works for me on i686-pc-linux-gnu with 3.2.3, 3.3.3, 3.0.4, 3.4.0, and 4.0.0.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WORKSFORME
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17499
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-09-24 13:10 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-15 10:55 [Bug c++/17499] New: long long constant broken L dot Gregory at Surrey dot ac dot uk
2004-09-17 18:09 ` [Bug c++/17499] " pyrodave at msn dot com
2004-09-17 18:53 ` wilson at specifixinc dot com
2004-09-17 18:55 ` pyrodave at msn dot com
2004-09-17 19:59 ` pyrodave at msn dot com
2004-09-17 20:16 ` schwab at suse dot de
2004-09-17 20:19 ` pyrodave at msn dot com
2004-09-18 5:02 ` pinskia at gcc dot gnu dot org
2004-09-24 13:10 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).