Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > stdint.h vs. stdio.h

Reply
Thread Tools

stdint.h vs. stdio.h

 
 
copx
Guest
Posts: n/a
 
      06-08-2006
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)..

 
Reply With Quote
 
 
 
 
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
Guest
Posts: n/a
 
      06-08-2006
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.

 
Reply With Quote
 
 
 
 
SM Ryan
Guest
Posts: n/a
 
      06-08-2006
copx <(E-Mail Removed)> 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.
 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      06-08-2006
copx <(E-Mail Removed)> 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.
 
Reply With Quote
 
copx
Guest
Posts: n/a
 
      06-09-2006
copx schrieb:
> How can you use printf/scanf/etc. while using stdint.h types?

[snip]

Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments