public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/3112: printf error for structs with "long long" members
@ 2001-06-10 17:26 ydi
  0 siblings, 0 replies; 3+ messages in thread
From: ydi @ 2001-06-10 17:26 UTC (permalink / raw)
  To: gcc-gnats; +Cc: zwei

>Number:         3112
>Category:       c
>Synopsis:       printf error for structs with "long long" members
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jun 10 17:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Yu Di
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Solaris 2.7,  Generic_106541-12 sun4u sparc SUNW,Ultra-60
>Description:
If we try to print several member variables in a struct, with one of them being "long long" type, the other member variable displays will be also wrong.

If the following program is compiled and executed, it outputs "0,20" instead of "20,10"

#include <stdio.h>
main()
{
        struct aaa {
                unsigned long long x;
                unsigned short y;
        } a;
        a.x = 20;
        a.y = 10;
        printf("%lu, %d\n", a.x, a.y);
/*We know that %lu can't work for a.x, but it shouldn't affect a.y. If we change the sentence to printf("%lf, ...), it will work correctly for both values */
}
>How-To-Repeat:
See our program in the description
>Fix:
N/A
>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c/3112: printf error for structs with "long long" members
@ 2001-06-15  2:36 Joseph S. Myers
  0 siblings, 0 replies; 3+ messages in thread
From: Joseph S. Myers @ 2001-06-15  2:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/3112; it has been noted by GNATS.

From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: Yu Di <ydi@eecs.uic.edu>
Cc: <gcc-bugs@gcc.gnu.org>,  <gcc-gnats@gcc.gnu.org>,  <zwei@eecs.uic.edu>
Subject: Re: c/3112: printf error for structs with "long long" members
Date: Fri, 15 Jun 2001 10:31:23 +0100 (BST)

 On Thu, 14 Jun 2001, Yu Di wrote:
 
 > Hi, thanks for the reply, but I still have a question. I know "%lu" is not
 > the correct format for "long long" variables, and that member will not get
 > displayed correctly. But the question is: why the second struct member is
 > also not displayed correctly?
 
 As I said, read the Application Binary Interface (ABI) specification for 
 your system.  You may find that longs take up four bytes of stack space 
 and long longs eight bytes, so if printf takes a long where you put a long 
 long, it will locate subsequent arguments incorrectly as well.  Or there 
 may be some other calling convention with a similar effect.
 
 -- 
 Joseph S. Myers
 jsm28@cam.ac.uk
 


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

* Re: c/3112: printf error for structs with "long long" members
@ 2001-06-11  4:11 jsm28
  0 siblings, 0 replies; 3+ messages in thread
From: jsm28 @ 2001-06-11  4:11 UTC (permalink / raw)
  To: jsm28, gcc-bugs, gcc-prs, nobody, ydi, zwei

Synopsis: printf error for structs with "long long" members

State-Changed-From-To: open->closed
State-Changed-By: jsm28
State-Changed-When: Mon Jun 11 04:11:31 2001
State-Changed-Why:
    Not a bug.  printf can't tell what type the arguments are
    except by the format string you give.  GCC will warn about
    the incorrect format string with -Wall.  See ISO 9899 and
    the ABI specification for your system.  The correct format
    specifier for unsigned long long is %llu, but I don't know
    whether your system supports it.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3112&database=gcc


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

end of thread, other threads:[~2001-06-15  2:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-10 17:26 c/3112: printf error for structs with "long long" members ydi
2001-06-11  4:11 jsm28
2001-06-15  2:36 Joseph S. Myers

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).