By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

How to implement your own preprocessor directive

P: n/a
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.
Jan 8 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 2008-01-08 01:19:42 -0500, _d***@yahoo.com said:
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
have you considered using a make file for this instead?

--

-kira

Jan 8 '08 #2

P: n/a
On Jan 8, 2:50 pm, Kira Yamato <kira...@earthlink.netwrote:
On 2008-01-08 01:19:42 -0500, _d...@yahoo.com said:
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

have you considered using a make file for this instead?

--

-kira
Hi,

But is it possible to prefix '#' sign in front?
-Dwin
Jan 8 '08 #3

P: n/a
_d***@yahoo.com wrote:
Does anyone know how to implement your own preprocessor directive?
Yes: You download the source code of an opensource compiler and modify
it to support your preprocessor directive.

However, the "standard" way of enhancing the preprocessor is not to
create a new # command, but to create a new #pragma sub-command. This is
because other compilers will simply ignore #pragmas they don't support
instead of giving an error message. If your #pragma has been designed
properly, any source code using it will still be portable.

Even then, you still probably have to modify and recompile the
compiler's source code for this. I don't understand why you would want
to do this, but whatever floats your boat.
Jan 8 '08 #4

P: n/a
On 2008-01-08 04:13:12 -0500, _d***@yahoo.com said:
On Jan 8, 2:50 pm, Kira Yamato <kira...@earthlink.netwrote:
>On 2008-01-08 01:19:42 -0500, _d...@yahoo.com said:
>>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

have you considered using a make file for this instead?

Hi,

But is it possible to prefix '#' sign in front?
I'm not suggesting that you write your own directive at all. Your
example of compressing a file does not affect that very same source
code directly. So, you could've written a Makefile with a target/rule
that compresses the input file before compiling the source. But that
is only that one example.

Exactly, what are you trying to do that requires you to make
nonstandard extensions instead of just doing things the standard way?

--

-kira

Jan 8 '08 #5

P: n/a
_d***@yahoo.com wrote in news:45581d28-9d9a-4422-96fb-
31**********@v67g2000hse.googlegroups.com:
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
Jan 8 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.