473,473 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Macro that Defines another on invocation

Hi,

I want to define a macro that defines another on invocation. Somthing
like this:

#define MACRO_NR_1(FLAG, VALUE) #define MACRO_NR_1_##FLAG(VALUE)
(VALUE+FLAG)

So that when I call MACRO_NR_1(10), the macro MACRO_NR_1_10 gets
defined. The macro above does not work.

Do you know how I may do this ?

Sincerely,
Aravindh

Nov 23 '05 #1
2 1257
On Tue, 22 Nov 2005 03:25:38 -0800, aravindh.k wrote:
Hi,

I want to define a macro that defines another on invocation. Somthing
like this:

#define MACRO_NR_1(FLAG, VALUE) #define MACRO_NR_1_##FLAG(VALUE)
(VALUE+FLAG)
# is, in fact, a pre-processor operator. It's operand should be one of the
function-like macro's parameters, the 'value' of which will then be
magically transformed into a string literal.

So this is definitely not going to work.
So that when I call MACRO_NR_1(10), the macro MACRO_NR_1_10 gets
defined. The macro above does not work.

Do you know how I may do this ?


You may not.

6.10.3.4 #3: "The resulting completely macro-replaced preprocessing token
sequence is not processed as a preprocessing directive even if it
resembles one."

The "resulting completely macro-replaced preprocessing token sequence"
being your fully processed macro replacement.

--
Pieter Droogendijk <pi****@binky.org.uk>
PGP/1E92DBBC [ Make way for the Emperor's Finest. ] binky.org.uk

Nov 23 '05 #2
dank u.

I will not try it again. I plan to use inline functions now.
Thanks for pasting the standard, now I know it cannot be done in ANSI C.

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
0
by: Fritz Bosch | last post by:
We are in the process of refactoring our GUI-based test application for radio equipment and are rewriting a significant part in Python. The new architecture will substantially be based on the...
3
by: John | last post by:
Please, consider this macro: #define mymacro(arg1, arg2) arg1 and arg2 Then it is used: mymacro(boys, girls) How is its expansion?
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
12
by: Laurent Deniau | last post by:
I was playing a bit with the preprocessor of gcc (4.1.1). The following macros expand to: #define A(...) __VA_ARGS__ #define B(x,...) __VA_ARGS__ A() -nothing, *no warning* A(x) -x ...
5
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing...
9
by: Two-Horned Unicorn | last post by:
The following code compiles and works as expected when compiled with gcc. /* empty-args.c */ #include <stdio.h> #define foo(x,y) puts("bar: x=\"" #x "\"; y=\"" #y "\"") #define bar(x) ...
16
by: mdh | last post by:
I have asked a few questions about Macros...and think what I have been missing ...and which all who have replied clearly understand...is that this is a Pre-processor action. Hopefully the above is...
0
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,...
0
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...
0
Oralloy
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,...
0
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...
0
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...
0
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,...
0
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...
0
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...
0
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 ...

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.