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

Summary: Windows headers are included after packing alignment change
Product: SDL Reporter: lectem
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.1   
Hardware: x86   
OS: Windows 10   
Attachments: SDL_stdinc.h patch

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