I have two DLLs compiled separately, one is compiled from Visual Studio 2008 and one is a mex file compiled from matlab.
Both DLLs have a header file which they include. when I take the sizeof()
the struct in one DLL it returns 48, and in the other it returns 64.
I've checked the /Zp
switch and in both compilations it is set to /Zp8
.
What other compiler switches may affect the size of a struct?
The struct is a simple POCO with no inheritance and no virtual functions.
Edit
The struct looks like this:
class LIBSPEC SGeometry
{
public:
std::vector<IGeometry> m_i;
uint N;
uint n_im, n_s;
};
In debug it sizeof()
returns 56 in both cases, in release, in the mex compilation it's 48, from VS it's 64.
I can tell matlab the exact compiler options to use when compiling the mex so it's not it.
Edit
After checking with offsetof, it turns out that the difference is in the size of the std::vector
. in one dll it's 32 and in the other it's 48.
Both dlls are x64.
Ok, so this is possibly the most obscure thing ever.
It turns out that matlab add /D_SECURE_SCL=0
to the compilation which disables something called 'secure iterators'
This in turn causes a difference of 16 bytes in the size of std::vector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With