%d in printf

Hello All,
I want to know the difference between %d and %"PRIdPTR" in C....
And I want to know where exactly is PRIdPTR used?
Is it similar to intptr_t?
I tried to google this,but didnt get much help




Thanks in advance
Any help is highly appreciated
Last edited on
%d in printf takes an integer from the values list and prints it.

%PRIdPTR is a macro added in C99, that generally expands to effectively %lld, which can be used as a way of specifying that you are passing an intptr_t.
So does it mean that intptr_t and PRIdPTR are almost the same thing?
And why use %PRIdPTR is we can easily write %lld?
I am sorry...But this is still not clear to me
From the Posix specification:
APPLICATION USAGE
The purpose of <inttypes.h> is to provide a set of integer types whose definitions are consistent across machines and independent of operating systems and other implementation idiosyncrasies. It defines, via typedef, integer types of various sizes. Implementations are free to typedef them as ISO C standard integer types or extensions that they support. Consistent use of this header will greatly increase the portability of applications across platforms.

RATIONALE

The ISO/IEC 9899:1990 standard specified that the language should support four signed and unsigned integer data types- char, short, int, and long- but placed very little requirement on their size other than that int and short be at least 16 bits and long be at least as long as int and not smaller than 32 bits. For 16-bit systems, most implementations assigned 8, 16, 16, and 32 bits to char, short, int, and long, respectively. For 32-bit systems, the common practice has been to assign 8, 16, 32, and 32 bits to these types. This difference in int size can create some problems for users who migrate from one system to another which assigns different sizes to integer types, because the ISO C standard integer promotion rule can produce silent changes unexpectedly. The need for defining an extended integer type increased with the introduction of 64-bit systems.
http://pubs.opengroup.org/onlinepubs/009604599/basedefs/inttypes.h.html


Moral of the story: Strongly favour the type-safe and portable C++ input/output library over its type-unsafe and error-prone C counterpart.
Topic archived. No new replies allowed.