473,626 Members | 3,191 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 3228

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 "appreciate d."

--
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
2979
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 spare the time, I would appreciate any comments (including words like evil and disgusting, if you think they are applicable :-}) on the example here. Kenny -
4
7168
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 get the basics down as well as some examples displaying how to simply read and write. But the next step appears exponential. I haven never done anything in VB, so any and all concepts and commands are completely foreign. I have been digging...
5
3478
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 the cursor was on in the datasheet at the time I executed the macro. So, the questions are: 1) In the macro, how to I get my hands on the record key or record data of the record the cursor was on in the datasheet at the time I executed the...
1
1386
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. Please help Moty
6
10711
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
2044
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 data again and delete the unwanted data and repeat few more times in new sheets. End product will be apprximately 7 or 8 sheets - 1 for Active Customers, Inactive Customers, Pending Installs, Etc... I'm getting hung up I believe with naming...
2
1097
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 the value is between 0% and 100%. I also need the macro to give the user a message if a mistake occurs (using MsgBox).... I've done the first part, using IsNumeric, but I can not figure out how to do the other instructions.. Please help me out, Close...
2
1948
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 a month (cell B4) and the other has a year(cell B5). The macro that I have works great for searching just the month, but I don't know how to change it to incorporate another cell with the year in it. I really appreciate the help this forum...
1
3224
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 but it didn't work to reset the printer settings. Click on File then Print Click on Properties to get to the Printing Preferences and under Printing Shortcuts select Letterhead Setting then OK and OK again.
0
8268
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
8707
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, 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...
0
8641
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...
0
8510
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...
1
6125
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
5575
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();...
0
4093
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...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.