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 2755 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(id) \
BOOST_PP_EXPR_IIF( \
BOOST_PP_COMPL( \
BOOST_PP_IS_NULLARY( \
BOOST_PP_CAT(LIBRARY_MACRO_, id) \
) \
), \
X BOOST_PP_CAT(m_, X) \
) \
/**/
#define LIBRARY_MACRO_alpha ()
LIBRARY_MACRO(alpha) // 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******@comcast.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(id) \ BOOST_PP_EXPR_IIF( \ BOOST_PP_COMPL( \ BOOST_PP_IS_NULLARY( \ BOOST_PP_CAT(LIBRARY_MACRO_, id) \ ) \ ), \ X BOOST_PP_CAT(m_, X) \ ) \ /**/ #define LIBRARY_MACRO_alpha ()
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**********@Home.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 incomprehensible 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.com, 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/googlegroupsreply/> 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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
...
|
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...
|
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...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
header("Location:".$urlback);
Is this the right layout the...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
| |