Alignment problems

S

Stephen Sprunk

Very nice, but even this cannot be used to get the alignment of a
struct with a flexible array member, as such a struct cannot be a
member of another struct. Anyone have suggestions how to deal with
those?

Also, is there some magic (for a custom memory allocator) to find out
what would be the greatest alignment that any object can require?

Is there any real-world system for which one couldn't simply take the
maximum alignment of long long, long double, void*, and a function pointer?

S
 
A

Alexander Klauer

Keith said:
In this context, "correctly aligned" refers to the alignment of
the object to which the pointer points, not the alignment of the
pointer object itself. Functions aren't objects, so they don't have
an alignment. (Well, they might, but there's no way to generate
a misaligned pointer-to-function, so it's not a language-visible
issue.)

Conversions operate on values, so the alignment of an object whose
value is being converted is irrelevant to pointer conversions.
(If a pointer object is misaligned, you get undefined behavior when
you access it.)

You still need to worry about the alignment of pointer *objects*,
including pointer-to-function objects.

Ah, OK, I misunderstood what these paragraphs meant. With your explanation,
they make more sense. Thank you.
 
S

Serve Laurijssen

Kenneth Brody said:
I was surprised to see that statement, since I know MSVC supports inline.
However, a quick check confirms that "inline" is only available in C++
mode of MSVC. (At least in MSVC 2010. I didn't check the other versions
I have.) They do, however, support "_inline" in both C and C++ modes.

I believe you can check if _MSC_VER is defined, in which case you're using
a Microsoft C compiler, and "#define inline _inline" if you so desire.

or save all that hassle and use a macro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,220
Latest member
AugustinaJ

Latest Threads

Top