| Issue 42: | Why are the SDL records declared to be packed? | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Well, the summary says it all. These records should not be packed. I note the presence of various Pad fields. That's the tell-tale sign that the records are declared incorrectly. Just imagine the fun you'll have the day you try to compile for 64 bit. On the other hand, if you just removed packed everywhere, removed all the Pad fields, it would all be golden.
Sep 10, 2012
Not so in SDL 1.2.15 (http://www.libsdl.org/download-1.2.php), which looks like this: typedef struct SDL_PixelFormat { SDL_Palette *palette; Uint8 BitsPerPixel; Uint8 BytesPerPixel; Uint8 Rloss; Uint8 Gloss; Uint8 Bloss; Uint8 Aloss; Uint8 Rshift; Uint8 Gshift; Uint8 Bshift; Uint8 Ashift; Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; Uint32 Amask; /** RGB color key information */ Uint32 colorkey; /** Alpha value information (per-surface alpha) */ Uint8 alpha; } SDL_PixelFormat; But that struct looks very different from yours. Probably you are using a rather different revision of SDL. It all looks rather bogus to me.
Sep 10, 2012
That's right. I'm using SDL 1.3, which involved a pretty significant API overhaul. 1.3 was a transitional release; the current version is 2.0. I've already updated the SDL units on my end for full SDL2 compatibility, but they haven't been checked in yet. If you compare this against the C headers for SDL 1.3 or 2.0, you'll see they match correctly.
Sep 10, 2012
The SDL headers don't pack the structs. But some of the records in sdl_13.pas are. Anyway, you clearly know more than me so I'm no doubt not being helpful. Was trying to be though! |
These are taken directly from the definitions in the C headers. For example: typedef struct SDL_PixelFormat { Uint32 format; SDL_Palette *palette; Uint8 BitsPerPixel; Uint8 BytesPerPixel; <b>Uint8 padding[2];</b> Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; Uint32 Amask; Uint8 Rloss; Uint8 Gloss; Uint8 Bloss; Uint8 Aloss; Uint8 Rshift; Uint8 Gshift; Uint8 Bshift; Uint8 Ashift; int refcount; struct SDL_PixelFormat *next; } SDL_PixelFormat; So if I tried to recompile for 64-bit, they would still be correct.