tags:

views:

144

answers:

4

typedef unsigned long long IMSI;

IMSI imsi;

when i am trying to print this using %llu as a format specifier, i am getting a rather unrelated value.

What can i do to remove this problem?

I am also using gcc 4.3.3 I though there might be a problem with the tracing mechanism that i have been using, but i am getting the same problem even when using printf.

    imsiAsInt = 9379666465 ;
    brrm_trace(ubm_TRACE_BRRM_UECTRL,ubm_TRACE_INFO,
              UEC_IUH_ACCACHE_ENTRY_FOUND,imsiAsInt, status.ueRegCause,
              mCacheEntries.size());
    printf("printf:UEC_IUH_ACCACHE_ENTRY_FOUND=%llu, sizeof(IMSI)=%d\n",
            imsiAsInt,sizeof(IMSI));

This gives following output UEC_IUH_ACCACHE_ENTRY_FOUND Imsi=789731873,UeRegCause=1,CurSize=5 -->The trace printf:UEC_IUH_ACCACHE_ENTRY_FOUND=789731873, sizeof(IMSI)=8 ---> when using printf

Also for smaller values in 7 digits i am not getting any issue.

+1  A: 

What can i do to remove this problem?

You can post your code and fix your acceptance rate.

Alex
should be a comment
anon
@Neil, you're right -- but I'll edit it once he posts code.
Alex
Why would anyone upvote this? Votes for a future answer?
UncleBens
No, but perhaps it will help other question-askers *do the right thing* (TM)?
Alex
A: 

You didn't say what OS or compiler you're using, and you haven't posted the code, so giving a correct answer is not easy. I'll have a stab at it though and guess that you're using an old version of MSVC that doesn't support the standard printf format specifiers for long long and you may therefore have to use the non-standard Microsoft alternative of %Lu to get the desired result.

For future reference you should post your code, and give enough detail for people to answer e.g. what OS and compiler you are using. As others have noted you should also do something about your accept rate.

Paul R
A: 

Which compiler are you using? The following program

#include <stdio.h>
int main()
{
  unsigned long long x;

  x = 12345;
  printf("Value: %llu\n", x);

  x = -1;
  printf("Value: %llu\n", x);

  return 0;
}

does give the expected output:

Value: 12345
Value: 18446744073709551615

on Linux with gcc 4.4.3

Michael Ulm
I also get the same output for the program pasted above.Actually i am not using printf directly.We have our own tracing mechanism and this might well be a problem with that.I will check where the problem exists and then see what to do.Thanks a lot u guys for such quick response.
Abhijeet
+1  A: 

This could be a problem:

imsiAsInt = 9379666465 ;

[Warning] integer constant is too large for 'long' type 

Try 9379666465ll

UncleBens
+1 assuming that it's 32-bit integers this is definitely a problem. It should be ULL though since the type is unsigned.
Mark B