Fwd: Re: stdargs x86-64 question
Bob Plantz
plantz@cds1.net
Sun May 16 16:44:00 GMT 2010
Yes, you need "l=0x%016lx\n".
When I tried your original code I got the warning messages (after adding
#include <stdio.h>):
bob@bob-workstation:~/Desktop$ gcc -o pass pass.c
pass.c: In function âfâ:
pass.c:13: warning: format â%08lxâ expects type âlong unsigned intâ, but
argument 2 has type âintâ
pass.c:17: warning: format â%016xâ expects type âunsigned intâ, but
argument 2 has type âlong intâ
BTW, to be completely consistent, you should also change "i=0x%08x\n".
I'm using:
bob@bob-workstation:~/Desktop$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
--Bob
> Am Sonntag, den 16.05.2010, 10:44 +0200 schrieb phi benard:
>
> > execution:
> > CX48$ ./c
> > i=0x04030201
> > l=0x0000000005060708<<======= ????
> >
> > What am I doing wrong here?
> > On other OS/Architectures I got 0x0102030405060708
>
> Are you sure that %x takes 64bit numbers ?
> maybe %lx works..
>
> > { i=va_arg(ap,int);
> > printf("i=0x%08lx\n",i);
> > }
> Here you use 0x08lx ...
>
> > { l=va_arg(ap,long);
> > printf("l=0x%016x\n",l);
> > }
> Here you use 0x016x .. try 0x016lx
>
> l for long .. but ! on a 32bit system it's 32bits long !
> so you would need to use ll for long long..
>
> http://en.wikipedia.org/wiki/64-bit -> "Specific C-language data models"
>
> Luca.
>
>
More information about the Gcc-help
mailing list