GCC-3.X C preprocessor

Graeme Peterson gp@qnx.com
Thu Jan 31 07:55:00 GMT 2002

Hi, all.

It looks like the gcc-3.X C preprocessor has changed from 
string to token based.  This is causing us some grief here
at QNX, as we have recently begun using the concatenation in 
some of our system header files to build include paths.

When we build binaries to run on non-QNX cross development
hosts (like Solaris or Cygwin), we build them on that host,
and we sometimes need to refer to the QNX target system headers
rather than the host system header files. Since there's a great 
deal of overlap in the header file names (since we're a POSIX system),
making sure that the QNX headers are used, especially when our header 
files include other header files is problematic.

What we are doing is not strictly C compliant, but it works
with the gcc-2.X preprocessor, and also with the Watcom token
based preprocessor, and it is really handy.

In our cross dev Makefiles:

 CCFLAGS += -D_NTO_HDR_DIR_=$(USE_ROOT_nto)/usr/include/

in our source:

 /* Two step process because of standard C macro expansion rules */
 #define ___SPLICE(x,y)  x##y
 #define __SPLICE(x,y)   ___SPLICE(x,y)

 #ifdef _NTO_HDR_DIR_
  #define _NTO_HDR_(hdr)  <##__SPLICE(_NTO_HDR_DIR_,hdr)##>
  #define _NTO_HDR_(hdr)  <##hdr##>

 // include host system headers
 #include <string.h>
 #include <malloc.h>
 #include <stdio.h>
 #include <stdlib.h>

 // include qnx6 (nto) system headers,
 // which may in turn '#include _NTO_HDR_(some_nto.h)'
 #include _NTO_HDR_(gulliver.h)
 #include _NTO_HDR_(sys/elf.h)
 #include _NTO_HDR_(sys/elf_dyn.h)
 #include _NTO_HDR_(sys/elf_notes.h)
 // etc...

Even though this is not strictly legal, it has proven very
useful for our cross development.  Our Makefiles set $(USE_ROOT_nto)
based on where the cross dev tools are installed, so it is quite
portable for us.  

Any chance of getting it added back into the preprocessor as a GNU 
extension, or feature, or something?  Anyone else like to throw their 
vote in for this?

Graeme Peterson
QNX Tools group.

Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com

More information about the crossgcc mailing list