Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSVC: what compiler switches affect the size of structs?

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.

like image 742
shoosh Avatar asked Jan 24 '23 00:01

shoosh


2 Answers

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

like image 155
shoosh Avatar answered Jan 25 '23 13:01

shoosh


  • Check for differences in the include and library paths
  • Check for differences in defined preprocessor symbols
  • Check for any differences in the project settings (code generation, linkage etc.)
  • Do compile both versions with the same IDE on the same machine?
like image 35
RED SOFT ADAIR Avatar answered Jan 25 '23 13:01

RED SOFT ADAIR