473,769 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_nam e<parameters, ...>

ie. #compress input_file output_file

Thanks.
Jan 8 '08 #1
5 4001
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_nam e<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...@earthl ink.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_nam e<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...@earthl ink.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_n ame<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**********@v6 7g2000hse.googl egroups.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_nam e<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
9855
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 advice what to do?? mailto: doberman@nest.ntu-kpi.kiev.ua
16
4504
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 following example. eg cosider 2 files sample.c and sample.h sample.h
13
2136
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 defined = 2;
2
4925
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: SOMETHING
7
4900
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 linux. -- Dmitri
6
3135
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
2280
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 Portuguese, the msado15.dll is located at <drive>:\Arquivos de programas\Arquivos comuns\System\ADO\msado15.dll I'd know if exists some preprocessor directive that could identify the language of Windows and import msado15.dll from the correct...
31
2931
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 statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
7
621
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: #ifndef uint64 #warning 64-bit mode not supported. #endif
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.