Kochise wrote:
I imagine it would be kind to pack the whole struct in a #pragma pack(1) fashion for message-passing, yet rendering it useless for run-time usage due to alignment fault that could arise
IIRC, x86 doesn't actually care about alignment - it's more for performance issues. Certainly this little program runs on x86 and x64, using non-word alignment:
int main()
{
char x[] = {1,2,3,4,5,6,7,8};
int* pp = (int*)(x+1);
std::cout << std::hex << (*pp) << std::endl;
}
Alternatively - here's another thought - bit-fields:
typedef struct{ // size, offset 32 bits, offset 64 bits
int nCount : 32; // 4, 0, 0
int nMode : 16; // 2, 4, 4 <- ???
int sColor : 8; // 8, 8, 8
int pTest : 32; // 4, 16, 16
int aData0_3 : 32; // 10, 20, 24
int aData4_7 : 32; // 10, 20, 24
int aData8_9 : 16; // 10, 20, 24
}sStack,*psStack;
The array's been reconfigured slightly, but you could work around that.
Another option - serialize the struct to a byte-stream when sending, deserialize on the way back.
sStack Deserialize(BYTE* pBuffer, size_t nBytes)
{
_ASSERTE(nBytes >= 4 + 2 + 1 + 8 + 4 + 10);
sStack s;
s.nCount = *(int*)pBuffer;
// etc etc
return s;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p