473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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.
Jan 8 '08 #1
5 3970
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
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
_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
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
_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Boris Kuznetsov | last post by:
This occurs in an empty project when I add the following string: #using <mscorlib.dll> Can anyone tell me why would #using ... not be working???? MSDN says nothing about this error. Please...
16
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the...
13
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
2
by: Gustavo L. Fabro | last post by:
Greetings. Is there a way to run the preprocessor twice? Rephrasing that, is there a way to: #define SOMETHING #pragma OTHERTHING and have the preprocessor in somecode.cpp evaluate: ...
7
by: ddehterov | last post by:
Hello, I'm wondering, is #warning preprocessor command is documented in standart C or it's implementation specific? I cannot find any documentation about it. It works with gcc on freebsd and...
6
by: olivier.grant | last post by:
Hi All, I'm trying to define a macro that will allow me to write the following code : #include MY_MACRO( NAME, SPACE ) and end up with the following preprocessed code : #include NAME.hpp
6
by: 2112 | last post by:
I'm compiling a dll that imports msado15.dll. When I'm using Windows in English, the msado15.dll is located at <drive>:\Program Files\Common Files\System\ADO\msado15.dll". When using Windows in...
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
7
by: Daniel Rudy | last post by:
Hello Group, Is there a preprocessor directive that will cause the compiler to print a warning diagnostic of whatever message that I choose? I'm thinking of something along the lines of: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.