LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2013, 12:43 PM   #1
maheshgupta0248
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Rep: Reputation: 0
macro for defining enums


I have forgot the macro way for the following, can anyone help please me in this


#define DEF_INIT \
MY_DEF_INIT(INT1, "integer1", mychar1) \
MY_DEF_INIT(INT2, "integer2", mychar2) \
MY_DEF_INIT(INT3, "integer3", mychar3) \

#define MY_DEF_INIT(name, filename, variable)
typedef enum{
DEF_VALUE = 0,
DEF_INIT(name),
MAX_VALUES
}sampleEnum;


int main(){

}

sampleEnum should be preprocessed as following:
typedef enum{
DEF_VALUE = 0,
INT1,
INT2,
INT3,
MAX_VALUES
}sampleEnum;

I dont remember the exact syntax for above.

Thanks
 
Old 07-16-2013, 02:16 PM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by maheshgupta0248 View Post
sampleEnum should be preprocessed as following:
typedef enum{
DEF_VALUE = 0,
INT1,
INT2,
INT3,
MAX_VALUES
}sampleEnum;
I'm sorry, but as a personal favour to yourself I will not help you to abuse the preprocessor like that - I am certain that you cannot provide a compelling enough argument that doing it this way is worthwhile. You'll thank yourself for just writing out the enum you want.

On the other hand, maybe if you give an overview of what you're really trying to do, you'll get the answer you really want. But helping you do this would be like helping someone gnaw off their own leg - you might do it if their life depended on it, but you'd have to be pretty sure it was life or death.

Please, for your own sanity, just write the enum declaration out how you want it to be.

Last edited by JohnGraham; 07-16-2013 at 02:20 PM.
 
1 members found this post helpful.
Old 07-16-2013, 02:24 PM   #3
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Also - after having another look - it looks like what you might really want is an array of structs.
 
Old 07-16-2013, 04:27 PM   #4
maheshgupta0248
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by JohnGraham View Post
Also - after having another look - it looks like what you might really want is an array of structs.
John, firstly Im really sorry for my bad language. You are right I need array of stuctures also I got the help from the following link

http://www.embedded.com/design/progr...-macros-Part-1

Thanks for the help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help On Enums rohithzhere Programming 2 12-19-2007 12:48 PM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM
size of arrays/enums h/w Programming 6 12-21-2003 04:47 PM
Defining terms Kurt M. Weber General 1 10-25-2003 07:25 PM
Defining the Slices desbyleo Solaris / OpenSolaris 10 05-07-2003 09:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration