I recently had to work around the different default sizes used for enumerations in Delphi and c++ since i have to use a c++ dll from a delphi application.
One function call returns an array of structs (or records in delphi), the first element of which is an enum.
To make this work, I use packed records (or aligned(1)-structs). However, since delphi selects the size of an enum-variable dynamically by default and uses the smallest datatype possible (it was a byte in my case), but C++ uses an int for enums, my data was not interpreted correctly.
Delphi offers a compiler switch to work around this, so the declaration of the enum becomes
{$Z4}
TTypeofLight =
(
V3d_AMBIENT,
V3d_DIRECTIONAL,
V3d_POSITIONAL,
V3d_SPOT
);
{$Z1}
My Questions are:
- What will become of my structs when they are compiled on/for a 64-bit environment?
- Does the default c++ integer grow to 8 Bytes?
- Are there other memory alignment / data type size modifications (other than pointers)?
There is no 64bits compiler for Delphi so you can’t compile your program for 64bits. However, you can still compile it and run it on a 64bit OS as a 32 bits process. in that case, noting will happens to your structures.
The question of the library is a bit more complex: if you compile it as a 64 bits library, you won’t be able to load it in your 32-bits process at all. However, assuming you’re going to compile it for 64 bits and then use it from a 64 bits process, then the actual length of an int variable is most likely going to stay 32 bits (that’s not going to be the case for everything, though).
See this wikipedia article for some more information:
http://en.wikipedia.org/wiki/64-bit#Specific_data_models