LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-05-2013, 03:35 PM   #1
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Rep: Reputation: Disabled
Using GCC preprocessor to define a Literal inside a macro


I have the following setup:
Code:
#define OROR 66
#define LOGICAL(OP,OPCHR,LABEL) \
	case OP: \
		logic=1; \
		switch (lt){ \
		case INT: \
		switch (rt){ \
			case INT: \
				b=*lsi OPCHR *rsi; \
				break; \
			case FLT: \
				b=*lsi OPCHR *rflt; \
				break; \
			case STR: \
				error(ER_ILLEGAL_LOGIC,token,OP,get_linenum(prog)); \
				break; \
			case CHR: \
				b=*lsi OPCHR *rchar; \
				break; \
			default: \
LABEL:				syserror("arith",OP,get_linenum(prog),0); \
				break: \
			}   \
			return; \
		case FLT: \
		switch(rt){ \
			case INT: \
				b=*lflt OPCHR *rsi; \
				break; \
			case FLT: \
				b=*lflt OPCHR *rflt; \
				break; \
			case STR: \
				error(ER_ILLEGAL_LOGIC,token,OP,get_linenum(prog)); \
				break; \
			case CHR: \
				b=*lflt OPCHR *rchar; \
				break; \
			default: \
				goto LABEL; \
			} \
			return; \
		case STR:	\
		switch(rt){ \
			case INT: \
			case FLT: \
			case STR: \
			case CHR: \
				error(ER_ILLEGAL_LOGIC,token,OP,get_linenum(prog));        \
				break; \
			default: \
				goto LABEL; \
			} \
			return; \
		case CHR: \
		switch(rt){ \
			case INT: \
				b=*lchar OPCHR *rsi; \
				break; \
			case FLT: \
				b=*lchar OPCHR *rflt; \
				break; \
			case STR: \
				error(ER_ILLEGAL_LOGIC,token,OP,get_linenum(prog)); \
				break; \
			case CHR: \
				b=*lchar OPCHR *rchar; \
				break; \
			default: \
				goto LABEL; \
			} \
			return; \
		default: \
			goto LABEL; \
		} 
		

LOGICAL (OROR,||,loror)
Which expands to:
Code:
case 66: logic=1; switch (lt){ case 99: switch (rt){ case 99: b=*lsi || *rsi; break; case 100: b=*lsi || *rflt; break; case 101: error(10,token,66,get_linenum(prog)); break; case 102: b=*lsi || *rchar; break; default: loror: syserror("arith",66,get_linenum(prog),0); break: } return; case 100: switch(rt){ case 99: b=*lflt || *rsi; break; case 100: b=*lflt || *rflt; break; case 101: error(10,token,66,get_linenum(prog)); break; case 102: b=*lflt || *rchar; break; default: goto loror; } return; case 101: switch(rt){ case 99: case 100: case 101: case 102: error(10,token,66,get_linenum(prog)); break; default: goto loror; } return; case 102: switch(rt){ case 99: b=*lchar || *rsi; break; case 100: b=*lchar || *rflt; break; case 101: error(10,token,66,get_linenum(prog)); break; case 102: b=*lchar || *rchar; break; default: goto loror; } return; default: goto loror; }
I am getting the error: SWITCH QUANTITY NOT AN INTEGER

But it seems to expand to an integer so I don't understand the problem. Is it recursive use of the macro?


Any ideas you have would be greatly appreciated.

Last edited by schmitta; 12-05-2013 at 07:46 PM.
 
Old 12-05-2013, 11:04 PM   #2
schmitta
Member
 
Registered: May 2011
Location: Blacksburg VA
Distribution: UBUNTU, LXLE
Posts: 352

Original Poster
Rep: Reputation: Disabled
Was using pointers (lt and rt) in switch statement instead of a dereferenced pointer (*lt and *rt).
 
  


Reply

Tags
gcc, preprocessor variable



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
ATOMIC_INIT macro defined as a compound literal vilhelmgray Linux - Kernel 0 04-26-2013 11:45 PM
assembling a assembly code contain C preprocessor(#define) saeedsssss Programming 5 02-11-2013 02:44 AM
Understand Define Macro in moduleparam.h in C minivy Linux - Software 4 11-21-2011 05:57 PM
Macro #if versus #define question in C dman777 Programming 4 08-08-2011 02:02 PM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM

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

All times are GMT -5. The time now is 09:49 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