Search code examples
clinuxapr

How to printf the "apr_uint32_t"?


My question is: How to printf the "pMessage","aiLength","szDataSize"?

EventInfo* pEventInfo

typedef struct {
        char* pMessage;
        SocketHeader* pSocketHeader;
        PipeHeader* pPipeHeader;
} EventInfo;

typedef struct {
        apr_uint32_t aiLength;
} PipeHeader;

typedef struct {
        apr_uint32_t szDataSize;
} SocketHeader;

What is the "apr_uint32_t"?


Solution

  • While I think @pilcrow's answer - using C99 format string conversion specifiers in <inttypes.h> - is probably the most elegant, the unsigned long type is guaranteed to be at least 32 bits, so you could simply use the %lu specifier with a cast:

    printf("%lu\n", (unsigned long) value);
    

    Which doesn't require C99. That's not much of an issue today, but IIRC, APR doesn't assume a C99 compiler either, or they wouldn't have bothered rolling their own 'exact' types.