Mail Archives: djgpp/2002/02/22/23:16:55
Hi all :)
I recently created a macro for error reporting purposes, with different
behaviours for different systems.
But I've hit a little problem with the #ifdef's and #else's
I really don't think it's my mistake .. but could somebody point out what
it is I'm doing wrong?
---- error_macro.h ----
... // #ifndef wrappers
// the macro is defined properly if the following is changed to #ifdef ..
#ifndef _GNU_H_WINDOWS_H
// for non windows systems ..
#include <stdio.h>
#define p(s) { fprintf(stderr, "\nError in line %i of %s", \
__LINE__, __FILE__); \
fprintf(stderr, "\nReason : %s", #s); exit(1); }
#else // #ifdef _GNU_H_WINDOWS_H
// for windows ..
#define p(s) { MessageBox(NULL, #s, "Fatal Error", MB_OK); \
exit(1); }
#endif // #else // #ifdef _GNU_H_WINDOWS_H
... // #endif wrappers
---- end error_macro.h ----
---- windows.h ----
#ifndef _GNU_H_WINDOWS_H
#define _GNU_H_WINDOWS_H
... // other includes and stuff
#endif /* _GNU_H_WINDOWS_H */
---- end windows.h ----
---- test.c ----
#include <windows.h>
#include <stdlib.h>
#include <error_macro.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
p(x)
return 0;
} // WinMain()
---- end test.c ----
I'm using the gccw32 files.
By my reckoning, _GNU_H_WINDOWS_H is defined when windows.h is included in
test.c, and isn't #undef'ed anywhere else.
The error_macro.h file actually defines the macro for
non-windows (ie. #define p(s) { fprintf .. } ) instead of the windows
macro (ie. #define p(s) { MessageBox .. } ).
Because _GNU_H_WINDOWS_H is defined in windows.h and never #undef'ed, by
the time the pre-processor gets to the p(s) macro definitions it should go
to the #else section .. but it doesn't.
If I change the #ifndef _GNU_H_WINDOWS_H to #ifdef it works properly.
Surely that's not what's should be happening?
Hopefully somebody can point me in the right direction :)
Thanks in advance
DSK
- Raw text -