Re: Fwd: Re: stdargs x86-64 question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux