Mail Archives: djgpp/2001/05/04/17:06:04
-: > 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 -