Is there a portable way that only relies on what the C99 standard provides to find out the maximum required alignment that is needed for any data type.
Like maxalign_t
in C++11.
What I'm currently doing is calculating the least common multiple (lcm
) of the alignments of int
, long int
, long long int
, double
, void *
and size_t
as best effort way of determining the alignment.
Update:
I currently need this for implementing a wrapper around malloc
that stores metadata at the beginning of the block of memory and returns a pointer with a higher address than what malloc
has returned.