Quote:
Originally Posted by John@Wessex
There may be a need to do it in something like a device driver where, say, a DMA controller can only be given an address that lays on a certain alignment boundary.
That's a fair enough point.
However, the literal answer to the OP's question "How can we make sure that our function will allocate a block of bytes in the memory , and the address of the beginning of the block will always be divided by 16?" is that you cannot do it. ;)
I like Mark Pauna's solution that supplies an equivalent with a disclaimer for freeing the memory. I must admit though, if stuck with C then I would probably employ a memory pool to handle the returning of aligned pointers to dynamically allocated memory - for some reason it feels like a more contained solution. But I agree that if in C++ then a simple class for handling the memory management would be the most suitable solution.