(e-mail address removed) wrote in (e-mail address removed):
Hi,
Does anyone know how to implement your own preprocessor directive?
For instance, I would like to have a directive which goes like:
#<directive_name> <parameters, ...>
ie. #compress input_file output_file
Thanks.
The short answer is no. Not without writing your own non-standard
preprocessor. The point of the preprocessor is code generation prior to
actual compilation. Any other commands (such as compress) should be done
in your build environment and not by the C++ compiler. In general, your
best bet would be macros (see the boost PP library for an extensive set of
code generation macros). Alternately, you can invoke another text
processing language on the code before you compile it to get additional
effects. (awk, sed, perl, m4 come to mind). The problem with invoking
another macro language is that then to port your code, you have to be sure
there is a working version of your processing language on that platform.
joe