We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4159 - Windows headers are included after packing alignment change
Summary: Windows headers are included after packing alignment change
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.1
Hardware: x86 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-07 23:42 UTC by lectem
Modified: 2018-05-10 05:31 UTC (History)
1 user (show)

See Also:


Attachments
SDL_stdinc.h patch (2.00 KB, patch)
2018-05-09 11:40 UTC, Ozkan Sezer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description lectem 2018-05-07 23:42:28 UTC
The SDL_syswm.h header includes the windows.h header after including begin_code.h which changes the structure packing alignment.

It seems this is not safe as suggested by the following warning : 
warning C4121: 'JOBOBJECT_IO_RATE_CONTROL_INFORMATION_NATIVE_V2': alignment of a member was sensitive to packing 


While it might not be critical, it could result in hard to track bugs, I suggest moving the following code :

```
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#endif
```

before `#include "begin_code.h"`

This is also tracked on the VisualStudio tracker here: https://developercommunity.visualstudio.com/content/problem/245898/warnings-in-winnth-sdk-100171340.html
Comment 1 lectem 2018-05-07 23:48:47 UTC
It might actually be a good idea to not put this `#include "begin_code.h"` before any other system header in fact... So probably the same issue for X11, UIKit etc
Comment 2 Sam Lantinga 2018-05-08 02:26:26 UTC
Good point.

Fixed, thanks!
https://hg.libsdl.org/SDL/rev/eba3a7c4ba16
Comment 3 Ozkan Sezer 2018-05-09 11:40:25 UTC
Created attachment 3243 [details]
SDL_stdinc.h patch

For consistency, move the alloca() includes before begin_code.h in SDL_stdinc.h.
Comment 4 Ozkan Sezer 2018-05-10 05:31:13 UTC
(In reply to Ozkan Sezer from comment #3)
> Created attachment 3243 [details]
> SDL_stdinc.h patch
> 
> For consistency, move the alloca() includes before begin_code.h in
> SDL_stdinc.h.

Pushed this change as http://hg.libsdl.org/SDL/rev/a9203ed58516