[PATCH] Introduce __BIGGEST_ALIGNMENT__ macro
Arthur O'Dwyer
arthur.j.odwyer at gmail.com
Sat Dec 13 21:16:49 PST 2014
On Sat, Dec 13, 2014 at 2:56 PM, mats petersson <mats at planetcatfish.com> wrote:
> Ok, so how do you know WHAT to use as '__alignof__' in the C code that
> allocates memory for a void* with a size_t?
Why can't you just use the same technique that's already used by
malloc etc. on your platform of choice?
For example, both standard C and C++ support "max_align_t" — could you use that?
const size_t max_align = alignof(max_align_t);
In Clang specifically, you can also say something like
const size_t max_align = alignof(int __attribute__((aligned)));
I guess I have two opinions here. One is that this information is
already exposed via language constructs like max_align_t, so if you're
just coming from the perspective of an application programmer, you can
probably work with those language constructs and/or the old-school
"#define MAXALIGN 64" approach (make it 256 if you're really
paranoid).
But the other opinion is that since this information *is* already
known, at compile-time, by the compiler, and exposed via language
constructs, where's the harm in also exposing it via a preprocessor
#define? I don't think any arguments have really been given *against*
the idea of a GCC-style __BIGGEST_ALIGNMENT__.
Here's the StackOverflow post on the subject.
http://stackoverflow.com/questions/11656714/llvm-equivalent-of-gccs-biggest-alignment
my $.02,
–Arthur
More information about the cfe-commits
mailing list