Pregunta

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"?

¿Fue útil?

Solución

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.

Otros consejos

apr_uint32_t is a portable 32-bit unsigned integer from the Apache Portable Runtime project.

You ought to format it the same way you'd printf a native unsigned integer that you know for certain is 32 bits wide: use the PRIu32 format specifier as recommended in this answer.

(As a side note, other apr portable types come with their own platform-specific printf specifiers, e.g., apr_uint64_t has a corresponding APR_UINT64_T_FMT. However, this type does not.)

Try this

EventInfo eventInfo;
SockHeadExample sHead;
PipeHeader pipeHeader
printf("%s", eventInfo.pMessage);  // <- pMessage
printf("%u", sHead.szDataSize);    // <- szDataSize
printf("%u", pipeHeader.aiLength); // <- aiLength

Working

apr_uint32_t is unsigned int it is typedef by Apache library

Reference

apr_uint32_t is unsigned int, so you should know what to do next.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top