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

Re: Triggers status?

On Mon, Oct 29, 2007 at 04:11:25PM -0400, Phillip Susi wrote:
> Kurt Roeckx wrote:
>> You pass something different to printf().  In the first case you pass an
>> integer, in the second case you pass a pointer.  If sizeof(int) !=
>> sizeof(void *) you clearly have a problem.  The promotion rules does not
>> change it from interger to a longer type.  So if you want to pass a NULL
>> pointer you need to explicitly cast it.
> With va args, the arguments are always passed in a uniform size ( with 
> padding as needed ), which is MAX( sizeof( void * ), sizeof( long ) ), so 
> it doesn't make any difference.

I think you're talking about an implementations of stdargs here, not what
the standards says should happen.  Also, padding just means padding, not
zero or sign extending.

>> Try this on for instance amd64:
>> printf("%p %p %p %p %p %p %p %p\n", 1, (void *)2, 3, 4, 5, 6, 7, 8);
>> The result is:
>> 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x7fff00000008
> Seems to accept 1 and (void *)2 as pointers just fine.  What is with the 8 
> getting screwed up though?

On amd64, the first 6 integer parameters are passed in registers.  As you
can see in an other example, the 7th parameter can also be wrong.

>> Or:
>> printf("%p %p %p %p %p %p %p %p %p %p\n", 1, (void *)2, 3, 4, 5, 6, 7, 8, 
>> 9, 10);
>> gives:
>> 0x1 0x2 0x3 0x4 0x5 0x6 0x2b6c00000007 0x8 0x9 0x7fff0000000a
>> and:
>> printf("%p %p %p %p %p %p %p %p %p %p\n", 1, (void *)2, 3, 4, 5, 6, 7, 8, 
>> 9, (void *)10);
>> 0x1 0x2 0x3 0x4 0x5 0x6 0x2ba900000007 0x8 0x9 0xa
> Looks like a bug in the compiler to me.  It appears to be padding out the 
> integers to 64 bits like it should, but not zeroing the padding bits, 
> instead leaving them as undefined values.

Nothing says that they should be extended, and I don't see why a compiler
would go and fill data in something it shouldn't.  On the other hand
the standard does say that a char and a short should be prompted to an


Reply to: