473,499 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with c macro.

bob
Need help with c macro.

Have this call in my c program.

stub.c

SYMBOL(ALPHA) << no, dont want to change this to any other form.
SYMBOL(BETA)

Need a macro to expand each of above to this.

static struct somestruct struct_ALPHA = {"ALPHA"};
static struct somestruct struct_BETA = {"BETA"};
..
..

Cannot go beyond the following.

#define SYMBOL(ARG) \
static struct _CONCAT(struct_,ARG) = {?? what shud be here??};
Any help is appreciable.

Thx Bob.
Nov 14 '05 #1
3 3218

On Tue, 3 Feb 2004, bob wrote:

SYMBOL(ALPHA) << no, dont want to change this to any other form.
SYMBOL(BETA)

Need a macro to expand each of above to this.

static struct somestruct struct_ALPHA = {"ALPHA"};
static struct somestruct struct_BETA = {"BETA"};


Okay, so just copy down what you *want* to happen, and then
replace the ALPHA bits with some dummy identifier, and wrap the
whole thing in a #define:

#define SYMBOL(foo) \
static struct somestruct struct_##foo = { #foo };

That's all.

HTH,
-Arthur
Nov 14 '05 #2
fi*************@yahoo.com (bob) writes:
Need help with c macro.

Have this call in my c program.

stub.c

SYMBOL(ALPHA) << no, dont want to change this to any other form.
SYMBOL(BETA)

Need a macro to expand each of above to this.

static struct somestruct struct_ALPHA = {"ALPHA"};
static struct somestruct struct_BETA = {"BETA"};
..
..

Cannot go beyond the following.

#define SYMBOL(ARG) \
static struct _CONCAT(struct_,ARG) = {?? what shud be here??};


#define CONCAT(a,b) a ## b
#define STRINGIFY(a) #a
#define SYMBOL(arg) \
static struct somestruct CONCAT (struct_, arg) = { STRINGIFY (arg) };

If you don't need the argument to SYMBOL expanded in case it is a macro
itself, you can use a slightly simpler macro:

#define SYMBOL(arg) \
static struct somestruct struct_ ## arg = { #arg };

Martin
Nov 14 '05 #3
bob wrote:

Need help with c macro.

Have this call in my c program.

stub.c

SYMBOL(ALPHA) << no, dont want to change this to any other form.
SYMBOL(BETA)

Need a macro to expand each of above to this.

static struct somestruct struct_ALPHA = {"ALPHA"};
static struct somestruct struct_BETA = {"BETA"};
..
..

Cannot go beyond the following.

#define SYMBOL(ARG) \
static struct _CONCAT(struct_,ARG) = {?? what shud be here??};
#define SYMBOL(x) static struct somestruct CONCAT(struct_,x) = { #x };
#define CONCAT(x,y) x ## y

Note CONCAT instead of _CONCAT; to learn why, see

http://www.oakroadsystems.com/tech/c-predef.htm
Any help is appreciable.


ITYM "appreciated."

--
Er*********@sun.com
Nov 14 '05 #4

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

Similar topics

21
2955
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
4
7153
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to...
5
3470
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record...
1
1365
by: moty | last post by:
Do any body have a code example that illustrate the preprocessor of moving #define macro into the code. I need to replace all macro call (#define) in my code (file) with the macro code. ...
6
10703
by: zaheer031 | last post by:
Hi All, I need to define a macro as follows #define VERSION "1.0" #ifdef (VERSION == "1.0") #endif main() { }
0
2031
by: =?Utf-8?B?TGV0emRvXzF0?= | last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines, remove some lines based upon a condition in a certain column. Then copy this data into a new spreadsheet and sort the ...
2
1092
by: brokkoli88 | last post by:
Hi! I am having sort of a problem with a school assingnment. I need to create a macro that checks if the content in a cell is a number. If the value is a percentage, I need the macro to check if...
2
1922
by: jotr | last post by:
I recently received help writing a search macro for excel, but now I am trying to change it up to use it in another spreadsheet, and I am having some troubles. I need it to search two cells one has...
1
3208
by: sandyt57 | last post by:
I do Tech Support but do not know Visual Basic programming. In order to resolve a work process issue for one of our depts I need a macro that can do the following. I tried to create a macro in Word...
0
7130
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
7007
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
7171
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
7220
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
7386
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
5468
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,...
1
4918
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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.