How to move structs returned by real-mode services?
Q: My program uses the contents of a structure returned by a VBE function, but some of the struct members are garbled! A: Most probably, this happens because of incorrect declaration of the structure in your program. Many people copy a declaration from some real-mode program, and that is exactly what gets them into trouble. Here are some gotchas in this context: • The structure should be declared with __attribute__((packed)), to prevent GCC from inserting gaps between some members to make them properly aligned for faster access (see how gcc aligns structs). C programs can declare the entire struct with the packed attribute, but C++ programs will need to declare each member with it, see __attribute__((packed)). • If the real-mode struct has members which are pointers, you need to replace each pointer with a pair of an offset and a segment (in that order, due to Intel’s little-endian byte order). This is because real-mode far pointers cannot be used as protected-mode pointers: you cannot