[Prev][Next][Index]

extern "C" and #include




Here's another problem (are you tired of me yet?).

There are two files, bug4.pc and bug4.h. Here's bug4.pc:

	extern "C" {
	// include file defines TRUE and FALSE in an enum
	#include "bug4.h"
	};

	main()
	{
	  if (TRUE)
	    1 == 2;
	  else
	    1 == 3;
	}

and here's bug4.h:

	typedef enum { FALSE = 0, TRUE = 1 } mybool;

When compiled, this produces the error message

	blackrabbit(46) % pc++ bug4.pc
	Error on line 8 of bug4.pc:  Undefined symbol 'TRUE'
	Error in pc++ while executing:
	------->  pC++2dep  TEMP_pC++.C

When I remove the 'extern "C"' wrapper, it compiles fine.  Both CC and
gcc compile the program w/o compile-time errors.  The extern C wrapper
cannot easily be removed, as the include file is used with both C and
C++ and defines a lot of library functions written in C.

--lars