Hi.

On Sat, Jan 28, 2017 at 04:26:16PM +1100, Damian McGuckin wrote:
> What is the recommended most portable way to force memory alignment for a
> datum of any type, assuming one has a pointer say
> 
>       char *x
> 
> I currently use something like
> 
>       char *xany = aligntonext(x, sizeof(long))
> 
> where I use my own function 'aligntionext' which is defined below and I also
> assume that a 'long' will be the natural word-size of the machine and that
> any datum things just needs to align to this boundary. That said, if the
> second argument is say 4k, the function will align its result to a 4k
> boundary.
> 
> I was wondering if there is an optimal, better, more acceptable, or more
> portable, way.

Maybe posix_memalign(3) is API you are looking for.

Reply via email to