|
Boost : |
Subject: Re: [boost] [optional] memory use for optional refs and ptrs
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2010-10-06 19:23:16
On 06.10.2010, at 20:22, Stewart, Robert wrote:
> If any of the types, other than bool, were smaller than int, I think you'll find some differences, but the answer does depend upon compiler options.
No, and no.
First, this snippet:
struct I {
double d;
char c;
// expect 7 bytes padding
};
static_assert(sizeof(I) == 16, "Bad size for I");
struct O {
I i;
short s; // placed in padding?
};
If your theory is true, then the compiler would place s in the padding of i in the layout of O. Trying this out with Clang (which is ABI-compatible with GCC, so GCC would give the same result) shows that the size of O is 24, meaning that s is not placed in the padding.
I can't try MSVC. Maybe it does things differently.
Anyway, I can further state with conviction that no compiler for non-embedded platforms changes its ABI based on compiler options, except perhaps a compiler option intended to do specifically that. (Clang has an option to switch between various ABIs.) But no debug or optimization option will change the object layout algorithm. To do so would be pure insanity, because it would mean that you cannot link debug versions of code with non-debug versions, optimized versions with unoptimized ones.
Well, MSVC might do it. But even there I very much doubt it.
Sebastian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk