What is the sense of converting PVOID buffer to PCHAR?

c, c++, memory-alignment

Solution

You are not converting `PVOID` to `PCHAR`. You are converting an array of `PVOID`s (decaying to a `PVOID *`) to `PCHAR`.

PVOID alignedBuffer[BUFFER_SIZE/sizeof( PVOID )];

This defines `alignedBuffer` as an array of `PVOID`s (or `void *`s). As an array of pointers, it will be suitably aligned (usually 4-bytes on 32-bit, 8 bytes on 64-bit). If you do simply

CHAR buffer[BUFFER_SIZE];

There's no similar guarantee, since there's no alignment requirement for `CHAR`s.

Problem

I see next code in the MS code examples: ``` PVOID alignedBuffer[BUFFER_SIZE/sizeof( PVOID )]; PCHAR buffer = (PCHAR) alignedBuffer; hResult = FilterSendMessage( context->Port, &commandMessage, sizeof( COMMAND_MESSAGE ), buffer, sizeof(alignedBuffer), &bytesReturned ); ``` (alignedBuffer will hold the array of structures that are passed as replay to FilterSendMessage call) What is the sense of converting PVOID to PCHAR, does this helps with aligment, how?

Original source