public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43633]  New: sizeof returns wrong size for large long long values when using -std=c99
@ 2010-04-02 23:00 sje at cup dot hp dot com
  2010-04-02 23:04 ` [Bug c/43633] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sje at cup dot hp dot com @ 2010-04-02 23:00 UTC (permalink / raw)
  To: gcc-bugs

If I compile a program with -std=c99 and do a sizeof of a constant that is
larger then LONG_LONG_MAX but smaller then ULONG_LONG_MAX I get 16 instead of
8.  For values larger then ULONG_LONG_MAX I get 8.  I can reproduce this on x86
Linux and IA64 HP-UX (and probably other systems).    Here is a test case that
should show the problem on any systems where LONG LONG is 8 bytes.  Compiled
without -std=c99 all the prints will print '8', with '-std=c99' the middle two
prints will print out 16 instead of 8.  Reproducable with ToT and going back to
at least 4.1.0.

#include <stdio.h>
main()
{
        /* LONG_LONG_MAX */
        printf("%ld\n", sizeof(9223372036854775807LL));
        /* LONG_LONG_MAX + 1 */
        printf("%ld\n", sizeof(9223372036854775808LL));
        /* ULONG_LONG_MAX as a long long type */
        printf("%ld\n", sizeof(18446744073709551615LL));
        /* ULONG_LONG_MAX + 1 as a long long type */
        printf("%ld\n", sizeof(18446744073709551616LL));
}


-- 
           Summary: sizeof returns wrong size for large long long values
                    when using -std=c99
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sje at cup dot hp dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43633


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/43633] sizeof returns wrong size for large long long values when using -std=c99
  2010-04-02 23:00 [Bug c/43633] New: sizeof returns wrong size for large long long values when using -std=c99 sje at cup dot hp dot com
@ 2010-04-02 23:04 ` pinskia at gcc dot gnu dot org
  2010-04-03  9:16 ` schwab at linux-m68k dot org
  2010-04-05 12:55 ` truedfx at gentoo dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-04-02 23:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-04-02 23:04 -------
t.c:7:32: warning: integer constant is so large that it is unsigned
t.c:9:32: warning: integer constant is so large that it is unsigned
t.c:11:32: warning: integer constant is too large for its type


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43633


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/43633] sizeof returns wrong size for large long long values when using -std=c99
  2010-04-02 23:00 [Bug c/43633] New: sizeof returns wrong size for large long long values when using -std=c99 sje at cup dot hp dot com
  2010-04-02 23:04 ` [Bug c/43633] " pinskia at gcc dot gnu dot org
@ 2010-04-03  9:16 ` schwab at linux-m68k dot org
  2010-04-05 12:55 ` truedfx at gentoo dot org
  2 siblings, 0 replies; 4+ messages in thread
From: schwab at linux-m68k dot org @ 2010-04-03  9:16 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 538 bytes --]



------- Comment #2 from schwab at linux-m68k dot org  2010-04-03 09:16 -------
§6.4.4.1 Integer constants:

If an integer constant cannot be represented by any type in its list, it may
have an extended integer type, if the extended integer type can represent its
value. If all of the types in the list for the constant are signed, the
extended integer type shall be signed.

Thus 9223372036854775808LL will be of some signed extended type, since it does
not fit in long long.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43633


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/43633] sizeof returns wrong size for large long long values when using -std=c99
  2010-04-02 23:00 [Bug c/43633] New: sizeof returns wrong size for large long long values when using -std=c99 sje at cup dot hp dot com
  2010-04-02 23:04 ` [Bug c/43633] " pinskia at gcc dot gnu dot org
  2010-04-03  9:16 ` schwab at linux-m68k dot org
@ 2010-04-05 12:55 ` truedfx at gentoo dot org
  2 siblings, 0 replies; 4+ messages in thread
From: truedfx at gentoo dot org @ 2010-04-05 12:55 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 955 bytes --]



------- Comment #3 from truedfx at gentoo dot org  2010-04-05 12:54 -------
(In reply to comment #2)
> §6.4.4.1 Integer constants:
> 
> If an integer constant cannot be represented by any type in its list, it may
> have an extended integer type, if the extended integer type can represent its
> value. If all of the types in the list for the constant are signed, the
> extended integer type shall be signed.
> 
> Thus 9223372036854775808LL will be of some signed extended type, since it does
> not fit in long long.

It *may* have an extended integer type. If it doesn't (and it doesn't: gcc
doesn't have any of the standard's extended integer types, see
http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Integers-implementation.html), such
a constant is simply invalid, and gcc, after reporting that, is free to make
the code behave however it likes. At least, as far as the standard is
concerned.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43633


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-05 12:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-02 23:00 [Bug c/43633] New: sizeof returns wrong size for large long long values when using -std=c99 sje at cup dot hp dot com
2010-04-02 23:04 ` [Bug c/43633] " pinskia at gcc dot gnu dot org
2010-04-03  9:16 ` schwab at linux-m68k dot org
2010-04-05 12:55 ` truedfx at gentoo 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).