Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   stdint.h vs. stdio.h (http://www.velocityreviews.com/forums/t443039-stdint-h-vs-stdio-h.html)

copx 06-08-2006 05:34 AM

stdint.h vs. stdio.h
 
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)..


=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= 06-08-2006 05:56 AM

Re: stdint.h vs. stdio.h
 
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.


SM Ryan 06-08-2006 08:13 AM

Re: stdint.h vs. stdio.h
 
copx <no@spam.ru> 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 06-08-2006 08:17 AM

Re: stdint.h vs. stdio.h
 
copx <no@spam.ru> 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.

copx 06-09-2006 07:53 AM

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

[snip]

Thanks!



All times are GMT. The time now is 09:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.