C Include file problem

Programming, for all ages and all languages.
Post Reply
adw3221
Posts: 18
Joined: Thu Aug 31, 2006 11:02 am

C Include file problem

Post 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 :P) 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.

Code: Select all

#include <include\stdio.h>
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?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.
Every good solution is obvious once you've found it.
adw3221
Posts: 18
Joined: Thu Aug 31, 2006 11:02 am

Post by adw3221 »

But I do close them. And theres only one #ifdef so far.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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).
Every good solution is obvious once you've found it.
adw3221
Posts: 18
Joined: Thu Aug 31, 2006 11:02 am

Post 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]
adw3221
Posts: 18
Joined: Thu Aug 31, 2006 11:02 am

Post by adw3221 »

Well! I updated Watcom to OpenWatcom 1.6 and it works! Odd in how it would do that.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post 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.
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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).
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.
Every good solution is obvious once you've found it.
adw3221
Posts: 18
Joined: Thu Aug 31, 2006 11:02 am

Post 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.
adw3221
Posts: 18
Joined: Thu Aug 31, 2006 11:02 am

Post 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.
Post Reply