Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   How to implement your own preprocessor directive (http://www.velocityreviews.com/forums/t583050-how-to-implement-your-own-preprocessor-directive.html)

_dwin@yahoo.com 01-08-2008 06:19 AM

How to implement your own preprocessor directive
 
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.

Kira Yamato 01-08-2008 06:50 AM

Re: How to implement your own preprocessor directive
 
On 2008-01-08 01:19:42 -0500, _dwin@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


_dwin@yahoo.com 01-08-2008 09:13 AM

Re: How to implement your own preprocessor directive
 
On Jan 8, 2:50 pm, Kira Yamato <kira...@earthlink.net> wrote:
> 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

Juha Nieminen 01-08-2008 10:10 AM

Re: How to implement your own preprocessor directive
 
_dwin@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.

Kira Yamato 01-08-2008 12:35 PM

Re: How to implement your own preprocessor directive
 
On 2008-01-08 04:13:12 -0500, _dwin@yahoo.com said:

> On Jan 8, 2:50 pm, Kira Yamato <kira...@earthlink.net> wrote:
>> 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


Joe Greer 01-08-2008 02:07 PM

Re: How to implement your own preprocessor directive
 
_dwin@yahoo.com wrote in news:45581d28-9d9a-4422-96fb-
3191f56fc85a@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


All times are GMT. The time now is 06:54 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.