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
Sent from the SDL mailing list archive at Nabble.com.

Den Tue, 11 Aug 2009 17:01:29 -0700 (PDT)
skrev GMScribe <ali_lowe at 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

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/listinfo.cgi/sdl-libsdl.org


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

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
To: sdl at 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
Sent from the SDL mailing list archive at Nabble.com.


SDL mailing list
SDL at lists.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

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 :frowning:


Date: Tue, 11 Aug 2009 17:01:29 -0700
From: @GMScribe
To: sdl at 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
Sent from the SDL mailing list archive at Nabble.com.


SDL mailing list
SDL at lists.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


SDL mailing list
SDL at lists.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
Sent from the SDL mailing list archive at Nabble.com.