Page 1 of 1
C Include file problem
Posted: Tue Apr 24, 2007 12:23 pm
by adw3221
Hi all. My operating system runs on x86 and 68k machines and I'm having some difficulty with the x86 C code. Im using Watcom 11.0c (Im too lazy to upgrade
) and when using macros (#ifdef, #ifndef) I get an error message "Matching #endif in other source file". The 68k C compiler dosnt have a problem with this. Im using a windows batch file to build my OS. The include directory is at the source root and the source files are like this.
Now they all work fine but when I try to use macros as listed above in them they dont work. The macros work anywhere else but in include files.
Any ideas?
Posted: Tue Apr 24, 2007 12:32 pm
by Solar
A section starting with #ifdef / #ifndef continues until a #endif directive is found. The compiler is telling you that the section beginning at your #ifdef / #ifndef has its matching #endif in a different source file, i.e. you either didn't close it or tried to include a file within your #ifdef / #ifndef section.
Posted: Tue Apr 24, 2007 1:22 pm
by adw3221
But I do close them. And theres only one #ifdef so far.
Posted: Wed Apr 25, 2007 1:09 am
by Solar
1) Check that you don't #include within your #ifdef / #endif sequence. Check that you don't have a forgotten #ifdef / #ifndef / #endif lurking around somewhere (use 'grep').
2) Try gcc -E to stop compiling after the preprocessor stage (i.e., after includes, macro expansions, and #ifdef handling).
Posted: Wed Apr 25, 2007 12:12 pm
by adw3221
Theres only one #ifdef and #endif in the code. The include files dont include other files.
2) Try gcc -E to stop compiling after the preprocessor stage (i.e., after includes, macro expansions, and #ifdef handling).
Ill try that. I cant do that where I am right now.[/quote]
Posted: Mon Apr 30, 2007 10:03 am
by adw3221
Well! I updated Watcom to OpenWatcom 1.6 and it works! Odd in how it would do that.
Posted: Mon Apr 30, 2007 3:51 pm
by mystran
Solar wrote:1) Check that you don't #include within your #ifdef / #endif sequence. Check that you don't have a forgotten #ifdef / #ifndef / #endif lurking around somewhere (use 'grep').
It's perfectly acceptable to #include within an #if/#ifdef/#ifndef. Those are supposed to nest properly, and compilers that warn about #endif in a separate file do so because it's almost always a forgotten #endif. If a preprocessor cannot deal with #include withing #if/#ifdef/#ifndef block it's crap and should be replaced with something modern.
While I usually care about standards, in this case I'm going to stand by that opinion even if somebody points out that a certain standard disallows such constructs.
Posted: Mon Apr 30, 2007 4:06 pm
by Brynet-Inc
mystran wrote:It's perfectly acceptable to #include within an #if/#ifdef/#ifndef. Those are supposed to nest properly, and compilers that warn about #endif in a separate file do so because it's almost always a forgotten #endif. If a preprocessor cannot deal with #include withing #if/#ifdef/#ifndef block it's crap and should be replaced with something modern.
I do this quite frequently, I didn't even know such compilers existed that didn't support this..
Are you sure it wasn't just misconfigured Mike359? (
I have never used OpenWatcom).
Posted: Tue May 01, 2007 10:11 pm
by Solar
I didn't say that include-in-ifdef was "illegal", just that his problem could be in one of his include files instead of the source file he was looking at.
Posted: Wed May 02, 2007 11:18 am
by adw3221
Well I was configured correctly. I also have warnings set as errors. All I did was delete my Watcom directory and install the Open Watcom overtop of it and when I ran my build batch file it worked correctly.
Posted: Fri May 04, 2007 11:04 am
by adw3221
Strange thing is that the Watcom include files under 11.0c that come with the compiler use #Ifdefs and they don't have problems.