# Cleanup #include Windows.h proposal

**URL:** <https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524>\
**Category:** SDL Development\
**Created:** [August 12, 2009, 12:01am UTC](https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524 "2009-08-12T00:01:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GMScribe](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@GMScribe](https://discourse.libsdl.org/u/GMScribe)\
**Post date:** [August 12, 2009, 12:01am UTC](https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524/1 "2009-08-12T00:01:29Z")

</div>

Hi guys,

I’ve been trying to integrate some code of mine into SDL and have discovered  
that just by including SDL\_opengl.h in SDL\_sysvideo.h it brings up just  
under 100 warnings and errors. I’ve decided that it appears to be the early  
including of windows.h that is done in SDL\_opengl.h and sure enough, moving  
some of the defines over from sysvideo reduces the error count. However  
these are still some errors that I can assume are from other windows  
includes in other files where I’ve not copied over their defines to  
SDL\_opengl.h.

I would like to propose that we consolidate the setting up of windows  
defines and the including of windows.h into SDL\_config\_win32.h, as almost  
every sdl file includes SDL\_config.h (and thus config\_win32) as the very  
first line of code. Ultimately windows.h is only going to get included once  
so it’ll be a good idea for us to have control over when and be able to see  
all the defines in one location. This will help clear clutter from files  
that distract from the functional code and hopefully make future  
modifications easier by lessening the volatility of including windows.h out  
of order.

Does this proposal sound reasonable? If so I’ll look into making the  
changes. I suspect that similar measures could be taken for x11 etc as well.

Many thanks.–  
View this message in context: [http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24927834.html](http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24927834.html)  
Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Gerry\_Jo\_Jellestad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@Gerry\_Jo\_Jellestad](https://discourse.libsdl.org/u/Gerry_Jo_Jellestad)\
**Post date:** [August 12, 2009, 1:46am UTC](https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524/2 "2009-08-12T01:46:34Z")

</div>

Den Tue, 11 Aug 2009 17:01:29 -0700 (PDT)  
skrev GMScribe \<ali\_lowe at [sky.com](http://sky.com)\>:

> Does this proposal sound reasonable? If so I’ll look into making the  
> changes. I suspect that similar measures could be taken for x11 etc  
> as well.

Inclusion of X11 stuff should be avoided wherever possible. It likes  
to #define common english words and phrases, which wreaks havoc with  
cross-platform code that’s unaware of this.

- Gerry

---

<div class="post-metadata">

**Author:** ![GMScribe](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@GMScribe](https://discourse.libsdl.org/u/GMScribe)\
**Post date:** [August 12, 2009, 10:16am UTC](https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524/3 "2009-08-12T10:16:52Z")

</div>

Lol, exactly my point. Obviously protect the inclusion by OS sensitive  
defines, but by consolodating it to 1 file, we’re reducing the risk of such  
problems.

Gerry JJ wrote:\>

> Den Tue, 11 Aug 2009 17:01:29 -0700 (PDT)  
> skrev GMScribe \<@GMScribe\>:
> 
> > Does this proposal sound reasonable? If so I’ll look into making the  
> > changes. I suspect that similar measures could be taken for x11 etc  
> > as well.
> 
> Inclusion of X11 stuff should be avoided wherever possible. It likes  
> to #define common english words and phrases, which wreaks havoc with  
> cross-platform code that’s unaware of this.
> 
> - Gerry
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
View this message in context: [http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24933585.html](http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24933585.html)  
Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![James\_Haley](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/e47c2d/32.png) [@James\_Haley](https://discourse.libsdl.org/u/James_Haley)\
**Post date:** [August 13, 2009, 7:22pm UTC](https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524/4 "2009-08-13T19:22:01Z")

</div>

I can only speak for my own project, but making windows.h visible through  
SDL\_config\_win32.h would cause my code to explode. Windows defines such  
symbols as “true”, “false”, and “byte” which are not reserved words in  
ANSI C, and thus my program should be free to use them so long as it is  
not trying to also use Win32 code in the same modules. Because my program  
is highly portable, this happens to be the case. Anywhere we do need  
Win32-specific code, for example getting the process path and name, or  
setting the process affinity mask so that SDL’s multicore-CPU audio  
crashes go away, that code is isolated in modules that do not include the  
conflicting definitions.

Bringing windows.h into every client module that uses SDL, whether it  
is needed or not, is just major namespace pollution and should really  
be thought about carefully. I’ve already had problems with this header  
in the past (first conflicting with a macro to replace malloc, and then  
again conflicting with the addition of a stdint.h/inttypes.h for Visual  
C++). I’d hate to see it blow up on me yet again :(----------------------------------------

> Date: Tue, 11 Aug 2009 17:01:29 -0700  
> From: ali\_lowe at [sky.com](http://sky.com)  
> To: sdl at [lists.libsdl.org](http://lists.libsdl.org)  
> Subject: [SDL] Cleanup #include Windows.h proposal
> 
> Hi guys,
> 
> I’ve been trying to integrate some code of mine into SDL and have discovered  
> that just by including SDL\_opengl.h in SDL\_sysvideo.h it brings up just  
> under 100 warnings and errors. I’ve decided that it appears to be the early  
> including of windows.h that is done in SDL\_opengl.h and sure enough, moving  
> some of the defines over from sysvideo reduces the error count. However  
> these are still some errors that I can assume are from other windows  
> includes in other files where I’ve not copied over their defines to  
> SDL\_opengl.h.
> 
> I would like to propose that we consolidate the setting up of windows  
> defines and the including of windows.h into SDL\_config\_win32.h, as almost  
> every sdl file includes SDL\_config.h (and thus config\_win32) as the very  
> first line of code. Ultimately windows.h is only going to get included once  
> so it’ll be a good idea for us to have control over when and be able to see  
> all the defines in one location. This will help clear clutter from files  
> that distract from the functional code and hopefully make future  
> modifications easier by lessening the volatility of including windows.h out  
> of order.
> 
> Does this proposal sound reasonable? If so I’ll look into making the  
> changes. I suspect that similar measures could be taken for x11 etc as well.
> 
> ## Many thanks.
> 
> View this message in context: [http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24927834.html](http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24927834.html)  
> Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

* * *

Get back to school stuff for them and cashback for you.  
[http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT\_MSHYCB\_BackToSchool\_Cashback\_BTSCashback\_1x1](http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1)

---

<div class="post-metadata">

**Author:** ![GMScribe](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@GMScribe](https://discourse.libsdl.org/u/GMScribe)\
**Post date:** [August 14, 2009, 3:37pm UTC](https://discourse.libsdl.org/t/cleanup-include-windows-h-proposal/16524/5 "2009-08-14T15:37:30Z")

</div>

This is a good point and is similar to the issues I’ve been experiencing. In  
my situation however, I have created a new module that requires windows.h  
when running on a win32 system. The issue here is that to interact with this  
code I must include my new module, however it’s introducing windows.h  
earlier than it should be. In a module the size of SDL I feel that we  
shouldn’t have to rely on compile order being correct as small changes could  
throw this out of balance.

I think something like a nestable opt-out of OS-specific defines definition  
should be added to those files that do not wish to see windows.h, however  
this would still require that they be called before files requiring  
windows.h. Another solution would be to include windows.h right away then  
redefine fairly generic code. Another possibility is of course to just  
off-limit various definitions.

Meanwhile I’ll look into adding my own defines to my module to avoid  
including windows.h. However I think a more permanent solution should be  
used if possible.

James Haley wrote:\>

> I can only speak for my own project, but making windows.h visible through  
> SDL\_config\_win32.h would cause my code to explode. Windows defines such  
> symbols as “true”, “false”, and “byte” which are not reserved words in  
> ANSI C, and thus my program should be free to use them so long as it is  
> not trying to also use Win32 code in the same modules. Because my program  
> is highly portable, this happens to be the case. Anywhere we do need  
> Win32-specific code, for example getting the process path and name, or  
> setting the process affinity mask so that SDL’s multicore-CPU audio  
> crashes go away, that code is isolated in modules that do not include the  
> conflicting definitions.
> 
> Bringing windows.h into every client module that uses SDL, whether it  
> is needed or not, is just major namespace pollution and should really  
> be thought about carefully. I’ve already had problems with this header  
> in the past (first conflicting with a macro to replace malloc, and then  
> again conflicting with the addition of a stdint.h/inttypes.h for Visual  
> C++). I’d hate to see it blow up on me yet again ☹
> 
> * * *
> 
> > Date: Tue, 11 Aug 2009 17:01:29 -0700  
> > From: @GMScribe  
> > To: sdl at [lists.libsdl.org](http://lists.libsdl.org)  
> > Subject: [SDL] Cleanup #include Windows.h proposal
> > 
> > Hi guys,
> > 
> > I’ve been trying to integrate some code of mine into SDL and have  
> > discovered  
> > that just by including SDL\_opengl.h in SDL\_sysvideo.h it brings up just  
> > under 100 warnings and errors. I’ve decided that it appears to be the  
> > early  
> > including of windows.h that is done in SDL\_opengl.h and sure enough,  
> > moving  
> > some of the defines over from sysvideo reduces the error count. However  
> > these are still some errors that I can assume are from other windows  
> > includes in other files where I’ve not copied over their defines to  
> > SDL\_opengl.h.
> > 
> > I would like to propose that we consolidate the setting up of windows  
> > defines and the including of windows.h into SDL\_config\_win32.h, as almost  
> > every sdl file includes SDL\_config.h (and thus config\_win32) as the very  
> > first line of code. Ultimately windows.h is only going to get included  
> > once  
> > so it’ll be a good idea for us to have control over when and be able to  
> > see  
> > all the defines in one location. This will help clear clutter from files  
> > that distract from the functional code and hopefully make future  
> > modifications easier by lessening the volatility of including windows.h  
> > out  
> > of order.
> > 
> > Does this proposal sound reasonable? If so I’ll look into making the  
> > changes. I suspect that similar measures could be taken for x11 etc as  
> > well.
> > 
> > ## Many thanks.
> > 
> > View this message in context:  
> > [http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24927834.html](http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24927834.html)  
> > Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> Get back to school stuff for them and cashback for you.  
> [http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT\_MSHYCB\_BackToSchool\_Cashback\_BTSCashback\_1x1](http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
View this message in context: [http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24973740.html](http://www.nabble.com/Cleanup--include-Windows.h-proposal-tp24927834p24973740.html)  
Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).
