Skip to content

PrintfCodes

Jeff Squyres edited this page Sep 7, 2015 · 7 revisions

Using the proper escape codes for printf()-like functions

Here is a list of the format types you should use for various types common in Open MPI.

Open MPI now requires a C99 compiler, in which <inttypes.h> is required. As such, all the escape sequences below are guaranteed to be available.

[If the format is in quotes (for example, "%d") it can be included directly in the format string, but if it is not (PRId32, it should be concatenated by the preprocessor, with a leading "%". For example:

#include <inttypes.h>

uint32_t foo = 1;
long bar = 1;
printf("foo: %" PRIu32 ", bar: %ld\n", foo, bar);
type format notes
int32_t PRId32
uint32_t PRIu32
int64_t PRId64
uint64_t PRIu64 / PRIx64 use u if an unsigned variable, x if a remote address
void* PRIxPTR / PRIuPTR Cast to (uintptr_t)
size_t PRIsize_t Might need to cast to unsigned long
Clone this wiki locally