www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/22/23:16:55

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: Dong Soo Kim <dsk666 AT cse DOT unsw DOT EDU DOT AU>
Newsgroups: comp.os.msdos.djgpp
Subject: GNU preprocessor problem?
Date: Sat, 23 Feb 2002 14:29:26 +1100
Organization: The University of New South Wales
Lines: 81
Message-ID: <Pine.GSO.4.44.0202231406580.7343-100000@mozart.orchestra.cse.unsw.EDU.AU>
NNTP-Posting-Host: mozart.orchestra.cse.unsw.edu.au
Mime-Version: 1.0
X-Trace: tomahawk.unsw.edu.au 1014434875 18569 129.94.242.14 (23 Feb 2002 03:27:55 GMT)
X-Complaints-To: abuse AT unsw DOT edu DOT au
NNTP-Posting-Date: Sat, 23 Feb 2002 03:27:55 +0000 (UTC)
X-X-Sender: dsk666 AT mozart DOT orchestra DOT cse DOT unsw DOT EDU DOT AU
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019