I need to write a macro that inserts
someStruct m_someStruct;
into another struct declaration.
The problem is that if the programmer specifies one particluar struct
(called alpha), nothing should be inserted.
So, is it possible to write a macro that does this:
MACRO(alpha) expands to nothing
MACRO(X) expands to X m_##X (for all values of X except alpha)
My guess is that it is impossible. But then, in the Boost preprocessor
package, they achieve some things that I would also have thought
impossible. :-)
This has to work in C, so I cannot use C++ templates.
--
Claus Tondering 8 2922 cl************* @gmail.com wrote On 03/17/06 09:26,: I need to write a macro that inserts someStruct m_someStruct; into another struct declaration.
The problem is that if the programmer specifies one particluar struct (called alpha), nothing should be inserted.
So, is it possible to write a macro that does this:
MACRO(alpha) expands to nothing MACRO(X) expands to X m_##X (for all values of X except alpha)
The expansion of a macro cannot produce preprocessor
directives, hence it cannot produce preprocessor conditionals.
However, you might be able to do something like
#define alpha /* nil */
#define m_alpha /* nil */
.... so that when MACRO(alpha) expands, each component of its
expansion is also a macro that then "expands" to nothing.
Personally, I don't think the preprocessor is the right
tool for this.
This has to work in C, so I cannot use C++ templates.
Why cross-post to comp.lang.c++, then? Followups
set to comp.lang.c only.
-- Er*********@sun .com cl************* @gmail.com wrote: I need to write a macro that inserts someStruct m_someStruct; into another struct declaration.
The problem is that if the programmer specifies one particluar struct (called alpha), nothing should be inserted.
So, is it possible to write a macro that does this:
MACRO(alpha) expands to nothing MACRO(X) expands to X m_##X (for all values of X except alpha)
Yes, it is possible:
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/control/expr_iif.hpp>
#include <boost/preprocessor/detail/is_nullary.hpp>
#include <boost/preprocessor/logical/compl.hpp>
#define LIBRARY_MACRO(i d) \
BOOST_PP_EXPR_I IF( \
BOOST_PP_COMPL( \
BOOST_PP_IS_NUL LARY( \
BOOST_PP_CAT(LI BRARY_MACRO_, id) \
) \
), \
X BOOST_PP_CAT(m_ , X) \
) \
/**/
#define LIBRARY_MACRO_a lpha ()
LIBRARY_MACRO(a lpha) // expands to nothing
LIBRARY_MACRO(X ) // expands to X m_X
Regards,
Paul Mensonides
On Sat, 18 Mar 2006 00:53:06 -0800, "Paul Mensonides"
<pm******@comca st.net> wrote: cl************ *@gmail.com wrote: I need to write a macro that inserts someStruct m_someStruct; into another struct declaration.
The problem is that if the programmer specifies one particluar struct (called alpha), nothing should be inserted.
So, is it possible to write a macro that does this:
MACRO(alpha) expands to nothing MACRO(X) expands to X m_##X (for all values of X except alpha)
Yes, it is possible:
#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/control/expr_iif.hpp> #include <boost/preprocessor/detail/is_nullary.hpp> #include <boost/preprocessor/logical/compl.hpp>
#define LIBRARY_MACRO(i d) \ BOOST_PP_EXPR_I IF( \ BOOST_PP_COMPL( \ BOOST_PP_IS_NUL LARY( \ BOOST_PP_CAT(LI BRARY_MACRO_, id) \ ) \ ), \ X BOOST_PP_CAT(m_ , X) \ ) \ /**/ #define LIBRARY_MACRO_a lpha ()
LIBRARY_MACRO( alpha) // expands to nothing LIBRARY_MACRO( X) // expands to X m_X
Regards, Paul Mensonides
Hmmm ... he said it needs to work in C ... does Boost compile as C
code?
--
Bob Hairgrove No**********@Ho me.com
Bob Hairgrove wrote: On Sat, 18 Mar 2006 00:53:06 -0800, "Paul Mensonides" Regards, Paul Mensonides
Hmmm ... he said it needs to work in C ... does Boost compile as C code?
The pp-lib is both C and C++ code. The rest of Boost is not.
Regards,
Paul Mensonides
With the small change that the X in your macro should be replaced by
id, it works beautifully! Thank you very much.
--
Claus Tondering
With the small change that the X in your macro should be replaced by
id, it works beautifully! Thank you very much.
--
Claus Tondering
With the small change that the X in your macro should be replaced by
id, it works beautifully! Thank you very much.
--
Claus Tondering cl************* @gmail.com wrote: With the small change that the X in your macro should be replaced by id, it works beautifully! Thank you very much.
I suppose we should be thankful that such an incomprehensibl e and
useless context free message, which was even stupidly cross-posted
to c.l.c++ and c.l.c, is short.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: seemanta dutta |
last post by:
Greetings C gurus,
I have used preprocessor directives since a very long time. But
whenever I see some professional piece of C code, the linux kernel for
example, I get literally confused by the amount of preprocessor
directives used in these code.
Can anyone please tell me how to actually use these preprocessor
directives in a more professional way like selecting particular lines
of code suited for some particular hardware etc...
|
by: Christopher Benson-Manica |
last post by:
If I have a symbol defined at preprocessing (assume it's all digits),
how can I make that symbol into a string constant for compiling?
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
|
by: ccwork |
last post by:
Hi all,
We can define some magic number with #define:
#define OPERATION_1 0x00000001
#define OPERATION_2 0x00000002
#define OPERATION_3 0x00000003
....
We can also do that with enum:
enum OPERATION
|
by: claus.tondering |
last post by:
I need to write a macro that inserts
someStruct m_someStruct;
into another struct declaration.
The problem is that if the programmer specifies one particluar struct
(called alpha), nothing should be inserted.
So, is it possible to write a macro that does this:
MACRO(alpha) expands to nothing
|
by: Jon |
last post by:
All,
Yes, it's more of the famous 'what do I do about magic_quotes' questions.
Anyways, here we go:
I've been a PHP developer for about a year now, and have grown to detest
magic_quotes for numerous reasons. So, in my applications now I simply use
..htaccess to turn magic_quotes_gpc off and I escape as needed from there.
My problem however has become what to do for FULLY portable applications.
| |
by: spibou |
last post by:
Is the output of the C preprocessor deterministic ? What I mean
by that is , given 2 compilers which conform to the same standard,
will their preprocessors produce identical output given as input
the same file ? If not then how much variation is allowed ? Is it
just a bit more or less white space here and there or could could
there be larger differences ?
If the output is not deterministic then is it possible that the output
of the...
|
by: josh |
last post by:
Hi, I've read that in the future the C++ will not more support the
preprocessor and now some preprocessor functionality have already been
implemented in the language itself. What are that?
Thanks.
|
by: Larry Hale |
last post by:
I've heard tell of a Python binding for libmagic (file(1) *nixy
command; see http://darwinsys.com/file/). Generally, has anybody
built this and worked with it under Windows?
The only thing I've been able to find is the python-magic module at
http://hupp.org/adam/hg/python-magic/.
Is this "THE" python-magic module. (It seems to be to me, but
obviously I don't know. :)
|
by: Rohit |
last post by:
Hi,
I am working on a switch module which after reading voltage through a
port pin and caterogizing it into three ranges(open,low or high),
passes this range to a function switch_status() with parameters value
and signal ID. Signal Id is used to get a user configurable parameter
inside a configuration file, which depends on the type of switch.
I have implemented it as under. Please ignore those magic numbers as I
have mimized logic to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |