Date: Wed, 3 Jul 2024 10:56:13 +0100
This is very much a half-baked idea but I'll just throw it out there
to float. . .
When I need to use the Win32 API, I create a separate source file and
call it "windows_bomb_chamber.cpp", and it's the only file in my
project that includes <Windows.h>. Then I create little wrapper
functions so that other source files can call Win32 API functions.
I have to do this because <Windows.h> includes the kitchen sink along
with massive use of preprocessor macroes. But what if we could include
a header file, and only keep the macroes we need? Something like:
#include <Windows.h> keep MAXPATH, APIENTRY
Basically what this would do, is include <Windows.h>, and then
"#undef" all the macroes except for MAXPATH and APIENTRY. However it
would not undefine any macroes which are required by the 'kept'
macroes, so for example if APIENTRY is defined as follows:
#define APIENTRY WINAPI
then it's as if you wrote:
#include <Windows.h> keep MAXPATH, WINAPI, APIENTRY
I have only envisaged the 'keep' feature to work with preprocessor
macroes, although I'd be open to discussion about how to keep
declarations and definitions. I mean say we have a header file as
follows:
// contents of monkey.h
extern int monkey;
extern int donkey;
And then we include it as follows:
#include "monkey.h" keep monkey
int main(void)
{
donkey = 666; // compiler error because 'donkey' not kept
}
That's my idea to selectively pluck from header files.
to float. . .
When I need to use the Win32 API, I create a separate source file and
call it "windows_bomb_chamber.cpp", and it's the only file in my
project that includes <Windows.h>. Then I create little wrapper
functions so that other source files can call Win32 API functions.
I have to do this because <Windows.h> includes the kitchen sink along
with massive use of preprocessor macroes. But what if we could include
a header file, and only keep the macroes we need? Something like:
#include <Windows.h> keep MAXPATH, APIENTRY
Basically what this would do, is include <Windows.h>, and then
"#undef" all the macroes except for MAXPATH and APIENTRY. However it
would not undefine any macroes which are required by the 'kept'
macroes, so for example if APIENTRY is defined as follows:
#define APIENTRY WINAPI
then it's as if you wrote:
#include <Windows.h> keep MAXPATH, WINAPI, APIENTRY
I have only envisaged the 'keep' feature to work with preprocessor
macroes, although I'd be open to discussion about how to keep
declarations and definitions. I mean say we have a header file as
follows:
// contents of monkey.h
extern int monkey;
extern int donkey;
And then we include it as follows:
#include "monkey.h" keep monkey
int main(void)
{
donkey = 666; // compiler error because 'donkey' not kept
}
That's my idea to selectively pluck from header files.
Received on 2024-07-03 09:56:25