printf anomaly
- From: indigodfw@xxxxxxxxx
- Date: 21 Feb 2007 17:24:14 -0800
Hi experts
Consider this piece of code
unsigned long data = 124; /* Data is actually part of a big struct but
to simplify */
printf(" %-5llu ", (unsigned long long)(data*1000));
<memory address say 60000000>: 00000000 00000D77 00000000
00000000
0xD77 is 3447
Assume data is at the beginning of memory address 60000000 and this is
a big endian machine (MIPS based).
The compiler is doing two load word from 60000000 and 60000000+4 and
then multiplying it by 1000 and then prints 3447000 which is not
expected.
My understanding is that the 1000 will default to int
Then it will be promoted to unsigned long (since on our platform long
and int are of same size)
then operation will be carried out in unsigned long (result I mean).
then *result* will be cast to unsigned long long and then it will be
passed to printf
(not sure how - this is MIPS based platform) and printf is a variadic
function.
I must be missing something or the compiler is broken?
1.Please help me understand what is going on.
2.And how can I fix it the right way.
Please advise.
Thanks in advance,
.
- Follow-Ups:
- Re: printf anomaly
- From: Dietmar Schindler
- Re: printf anomaly
- From: Jack Klein
- Re: printf anomaly
- From: Keith Thompson
- Re: printf anomaly
- From: indigodfw
- Re: printf anomaly
- Prev by Date: Re: standard way to determine depth in stack
- Next by Date: Re: printf anomaly
- Previous by thread: standard way to determine depth in stack
- Next by thread: Re: printf anomaly
- Index(es):
Relevant Pages
|