stdint.h vs. stdio.h

Discussion in 'C Programming' started by copx, Jun 8, 2006.

  1. copx

    copx Guest

    How can you use printf/scanf/etc. while using stdint.h types?

    I mean if you use int_least64_t for example; how do you know the proper
    format identifier?
    On a 64bit platform int_least64_t might be defined as "int" (%d) while
    on a 32bit platform it might be a "long int" (%ld)..
     
    copx, Jun 8, 2006
    #1
    1. Advertising

  2. copx wrote:
    > How can you use printf/scanf/etc. while using stdint.h types?


    Using the macros defined in <inttypes.h>

    > I mean if you use int_least64_t for example; how do you know the proper
    > format identifier?
    > On a 64bit platform int_least64_t might be defined as "int" (%d) while
    > on a 32bit platform it might be a "long int" (%ld)..


    It's extremely ugly, but:
    printf("%" PRIdLEAST64 "\n", (int_least64_t) 0);

    It's up to the implementation to define the macro as "d", "ld", or
    whatever is appropriate for that specific platform.
     
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Jun 8, 2006
    #2
    1. Advertising

  3. copx

    SM Ryan Guest

    copx <> wrote:
    # How can you use printf/scanf/etc. while using stdint.h types?
    #
    # I mean if you use int_least64_t for example; how do you know the proper
    # format identifier?
    # On a 64bit platform int_least64_t might be defined as "int" (%d) while
    # on a 32bit platform it might be a "long int" (%ld)..
    #
    #
    #

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    Don't say anything. Especially you.
     
    SM Ryan, Jun 8, 2006
    #3
  4. copx

    SM Ryan Guest

    copx <> wrote:
    # How can you use printf/scanf/etc. while using stdint.h types?

    You can cast to a known type.
    int_ZZ_t zork;
    printf("%lld\n",(long long)zork);

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    Don't say anything. Especially you.
     
    SM Ryan, Jun 8, 2006
    #4
  5. copx

    copx Guest

    copx schrieb:
    > How can you use printf/scanf/etc. while using stdint.h types?

    [snip]

    Thanks!
     
    copx, Jun 9, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Campbell
    Replies:
    6
    Views:
    706
    Frank Schmitt
    Jan 19, 2004
  2. making literals be a stdint size

    , Aug 25, 2003, in forum: C Programming
    Replies:
    8
    Views:
    389
  3. Scott David Daniels

    What GCC version had <stdint.h> defined?

    Scott David Daniels, Aug 26, 2004, in forum: Python
    Replies:
    10
    Views:
    5,720
    Scott David Daniels
    Aug 31, 2004
  4. Replies:
    18
    Views:
    1,933
    crazzybugger
    Oct 22, 2006
  5. GS
    Replies:
    19
    Views:
    1,675
    Gordon Burditt
    Dec 15, 2004
Loading...

Share This Page