Thread: Data type for 32 bit and 64 bit architecture

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    19

    Data type for 32 bit and 64 bit architecture

    Hi,

    I am using u64 (unsigned long long int) to store the following number
    val = (u64) 0x5152535455565758; - When i do print using %llu, it only print 5455565758. Few questions:

    1. The reason to print this is if storage value is more than the capacity. I checked limits.h and i see ULONG64 can take up to 18446744073709551615 which in hex is FFFFFFFFFFFFFFFF. Why is my printf() not printing the entire range?

    2. Does the size of data type vary on the machine architecture of gcc? (i assume architecture). Pleas throw some light on this.

    3. I wrote small program as follows (please ignore line numbers), it prints correctly.
    Code:
    #include <stdio.h>
      2 #include <limits.h>
      3 
      4 
      5 void main()
      6 {
      7     unsigned long long int val = 18446744073709551615;
      8 
      9     printf(" %d", sizeof(int));
     10     printf("\n ULONG = %lu", ULONG_MAX);
     11     printf("\n val in hex = %llx", val);
     12     printf("\n val in dec = %llu\n", val);
     13 
     14 }
     15
    Output:
    4
    ULONG = 18446744073709551615
    val in hex = ffffffffffffffff
    val in dec = 18446744073709551615




    When i compile this wth -m32 flasg, ULONG values goes to half but still other prints are working fine. Am i missing something here?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why are you doing 'sizeof( int )', and then everything else is using a 'long long int'? Are you also confusing ULONG with ULLONG? %lu isn't %llu.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You're compiling with gcc and it isn't complaining about void main?

    > When i compile this wth -m32 flasg, ULONG values goes to half but still other prints are working fine. Am i missing something here?
    Perhaps reading the manual?
    -m32
    -m64
    Generate code for a 32-bit or 64-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on
    any i386 system. The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture.
    For darwin only the -m64 option turns off the -fno-pic and -mdynamic-no-pic options.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    gcc would also be warning about the definition of val (assuming you have racked up warning levels)
    Code:
    unsigned long long int val = 18446744073709551615ULL;
    Depending on the gcc vintage, %llu style of format strings may not be supported (as a C99 feature).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-14-2011, 09:26 PM
  2. store string data as a short or other data type
    By robin2aj in forum C Programming
    Replies: 5
    Last Post: 04-07-2010, 11:02 AM
  3. data type for hex
    By cutelucks in forum C Programming
    Replies: 3
    Last Post: 04-29-2007, 07:57 PM
  4. Data type
    By Eavan Hyde in forum Windows Programming
    Replies: 2
    Last Post: 03-23-2004, 03:06 AM
  5. new data type
    By jackson in forum C++ Programming
    Replies: 4
    Last Post: 01-04-2003, 02:32 AM

Tags for this Thread