How to implement your own preprocessor directive

Discussion in 'C++' started by _dwin@yahoo.com, Jan 8, 2008.

  1. Guest

    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, 2008
    #1
    1. Advertising

  2. Kira Yamato Guest

    On 2008-01-08 01:19:42 -0500, 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
     
    Kira Yamato, Jan 8, 2008
    #2
    1. Advertising

  3. Guest

    On Jan 8, 2:50 pm, Kira Yamato <> wrote:
    > On 2008-01-08 01:19:42 -0500, 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, 2008
    #3
  4. 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.
     
    Juha Nieminen, Jan 8, 2008
    #4
  5. Kira Yamato Guest

    On 2008-01-08 04:13:12 -0500, said:

    > On Jan 8, 2:50 pm, Kira Yamato <> wrote:
    >> On 2008-01-08 01:19:42 -0500, 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
     
    Kira Yamato, Jan 8, 2008
    #5
  6. Joe Greer Guest

    wrote in news:45581d28-9d9a-4422-96fb-
    :

    > 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
     
    Joe Greer, Jan 8, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trying_Harder

    Preprocessor directive

    Trying_Harder, Oct 2, 2003, in forum: C Programming
    Replies:
    16
    Views:
    675
    Kevin Easton
    Oct 5, 2003
  2. =?Utf-8?B?RGF2ZQ==?=

    Extend the page directive attributes with your own?

    =?Utf-8?B?RGF2ZQ==?=, Aug 18, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    359
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Aug 19, 2006
  3. Replies:
    3
    Views:
    525
    Default User
    Mar 13, 2007
  4. Replies:
    1
    Views:
    384
    Ian Collins
    Mar 13, 2007
  5. David Filmer
    Replies:
    17
    Views:
    268
    J. Romano
    Aug 18, 2004
Loading...

Share This Page