leiflundgren
leiflundgren

Reputation: 2966

What was default variable boundary alignment in Visual Studio 6?

I am trying to upgrade old Visual Studio 6 projects. They use "default" memory-boundary alignment. However, it seems that defaults for Visual Studio 6 and 2013 are not the same.

Anyone know what the old default was?
align(1) ?

(I need to know this since during the migration we will have a mix of programs. They communicate by serializing C-structs to byte-arrays and passing the array between programs. If the alignments are different that will fail horribly.)

Upvotes: 0

Views: 359

Answers (2)

John Bollinger
John Bollinger

Reputation: 181199

As far as I can tell, Visual Studio's (default) layout and alignment rules have not changed between VS 6 and VS 2013. Structure members are laid out on boundaries governed by their natural alignment requirements (relative to the lowest address of the structure representation), subject to a maximum of 8 padding bytes between members. Structures' own alignment requirements are the same as the largest alignment requirement of any member. All that is pretty routine, as it ensures that aligning a structure also aligns all its members.

Therefore, if the two compilers produce different binary representations of structs declared the same way, then it's likely that something about the members is changing. For instance, the size of pointers will differ between code built for Win32 and for Win64; even if you ignore their values (as you would need to do when transferring data between machines), the differing sizes of any pointer members would be likely to alter structure layouts.

Look out especially for bitfields. The size of the underlying integer datatype is implementation dependent, plus bitfield widths interact in sometimes non-obvious ways to affect the number of such units that are required at a given position in a given struct.

Upvotes: 2

Craig Lebakken
Craig Lebakken

Reputation: 1943

According to MSDN "Structure Alignment" documentation:

The default pack size for Windows 3.x is 2, whereas the default for Win32 is 8.

Be aware that compiler options can be overridden with #pragma pack.

Upvotes: 2

Related Questions