delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/05/04/17:06:04

X-Authentication-Warning: kendall.sfbr.org: jeffw set sender to jeffw AT darwin DOT sfbr DOT org using -f
Date: Fri, 4 May 2001 16:08:23 -0500
From: JT Williams <jeffw AT darwin DOT sfbr DOT org>
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
Cc: djgpp AT delorie DOT com
Subject: Re: __DJGPP__ and MSDOS
Message-ID: <20010504160823.A19921@kendall.sfbr.org>
Mail-Followup-To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, djgpp AT delorie DOT com
References: <20010430093758 DOT A5379 AT kendall DOT sfbr DOT org> <Pine DOT SUN DOT 3 DOT 91 DOT 1010430192119 DOT 19343D-100000 AT is>
Mime-Version: 1.0
User-Agent: Mutt/1.2.5i
In-Reply-To: <Pine.SUN.3.91.1010430192119.19343D-100000@is>; from eliz@is.elta.co.il on Mon, Apr 30, 2001 at 07:23:20PM +0300
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

-: > My experiments lead me to believe that __MSDOS__ is defined `immediately'
-: > by the preprocessor (by virtue of using a gcc that was built for DOS),
-: > but that __DJGPP__ is not defined until I #include a *system* header.
-: 
-: That might be true (depending on what version of GCC do you use), but 
-: even if it is so, the necessary header is included by the preprocessor 
-: before anything else, because the specs file tells it to do so with the 
-: -isystem switch.
-: 
-: > I can validly #ifdef __MSDOS__ inside "foo.h", but I have to wait until
-: > _after_ <stdio.h> to validly #ifdef __DJGPP__?
-: 
-: No.  __DJGPP__ should work exactly like __MSDOS__.  If you see something 
-: else, please post a short test program.

Ok, there are two files `hello.[ch]' at the end of this note that I've
been using to reproduce the behavior described above.  I'm using stock
djdev2.03 with DOS 5.0.

% gcc --version
2.7.2.1

% bash --version
GNU bash, version 2.04.7(1)-release (i386-pc-msdosdjgpp)
Copyright 1999 Free Software Foundation, Inc.

1. Compile `hello.c' with headers #included in this order:
	#include "hello.h"
	#include <stdio.h>

% gcc -c hello.c
In file included from hello.c:1:
hello.h:6: warning: #warning Found msdos.   <-- does *not* see __DJGPP__
% gcc -o hello.exe hello.o
% ./hello.exe
hello, world
hello, djgpp   <-- but hello.c *does* see __DJGPP__
hello, dos

2. Compile `hello.c' with headers in this order:
	#include <stdio.h>
	#include "hello.h"

% gcc -c hello.c
In file included from hello.c:2:
hello.h:2: warning: #warning Found djgpp.   <--
hello.h:6: warning: #warning Found msdos.
% gcc -o hello.exe hello.o
% ./hello.exe
hello, world
hello, djgpp   <--
hello, dos

So, depending on header #include order, __DJGPP__ may not be defined
and available for #ifdef testing inside `hello.h'.

TIA
jeff williams

Files hello.h, hello.c:

% cat hello.h
#ifdef __DJGPP__
#warning Found djgpp.
#endif

#ifdef __MSDOS__
#warning Found msdos.
#endif

% cat hello.c
#include "hello.h"
#include <stdio.h>

int main(void)
{
	printf("hello, world\n");
#ifdef __DJGPP__
	printf("hello, djgpp\n");
#endif
#ifdef __MSDOS__
	printf("hello, dos\n");
#endif
	return 0;
}

- Raw text -


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