473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C Preprocessor - Cascaded Macros

I've been looking into cascaded macros and I can't seem to find if
what I'm doing is portable. I want to do something like:

#define THREE_ONES 1,1,1
#define ONE_TWO_THREE 1,2,3

#define JOIN_LISTS(a,b) JOIN_LISTS_PROCESSED(a,b)
#define JOIN_LISTS_PROCESSED(a1,b1,c1,a2,b2,c2) a1+a2,b1+b2,c1+c2

so that the statement:

{ JOIN_LISTS(THREE_ONES,ONE_TWO_THREE) },

will expand (one the first preprocessor pass) to:

{ JOIN_LISTS_PROCESSED(1,1,1,1,2,3) },

then expand on the second pass to:

{ 1+1, 1+2, 1+3 },

On my compiler (DJGPP) it works just fine - but is it portable? Do
all preprocessors use a similar replacement order?

--
michaelblackney at hotmail dot com
http://aburatan.sourceforge.net/
Latest version 0.95 2-5-4
Nov 14 '05 #1
1 1479
On Thu, 09 Sep 2004 16:08:15 -0700, Michael Blackney wrote:
I've been looking into cascaded macros and I can't seem to find if
what I'm doing is portable. I want to do something like:

#define THREE_ONES 1,1,1
#define ONE_TWO_THREE 1,2,3

#define JOIN_LISTS(a,b) JOIN_LISTS_PROCESSED(a,b)
#define JOIN_LISTS_PROCESSED(a1,b1,c1,a2,b2,c2) a1+a2,b1+b2,c1+c2
All of these definitions look portable. For maximum utility, you should
put in a lot more parentheses, like so:

(a1)+(a2),(b1)+(b2),(c1)+(c2)

Why? So you can have lists like this:
JOIN_LISTS_PROCESSED(x+5,2+3/2,5-6,4-23,5&6,7^2)

so that the statement:

{ JOIN_LISTS(THREE_ONES,ONE_TWO_THREE) },

will expand (one the first preprocessor pass) to:

{ JOIN_LISTS_PROCESSED(1,1,1,1,2,3) },

then expand on the second pass to:

{ 1+1, 1+2, 1+3 },

On my compiler (DJGPP) it works just fine - but is it portable? Do
all preprocessors use a similar replacement order?


I can't think of any reason a conforming compiler would misparse your
headers.
Nov 14 '05 #2

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

Similar topics

8
by: Bram Stolk | last post by:
Hi there, What could I use to parse CPP macros in Python? I tried the Parnassus Vaults, and python lib docs, but could not find a suitable module. Thanks, Bram
25
by: Sabyasachi Basu | last post by:
While trying to port some stuff from Unix to Windows, I encountered a strange behaviour of function macros with empty arguments. Here is a small snippet which illustrates the problem: #include...
4
by: Jakob Simon-Gaarde | last post by:
Some project includes files from different libraries lib1,lib2 and lib3 all having each there own version header file. I need to be able to pick up these values in a single define value...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
4
by: Jim Ford | last post by:
I have a single C file with the following code: int f2() { /* Blah-blah */ } int f1() { /* Blah-blah */
13
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the...
3
by: Avin Patel | last post by:
Hi, I have written C# code. And I have used preprocessor / macro in it. I want to get the C# code after processing preprocessor, I have defined durcng compile time. How can I get this code? ...
2
by: Prashant Mahajan | last post by:
I just wanted comments from you all on the following topic: Let's say we have 2, C code files namely file1.c and file2.c. file1.c contains few pre-processor definations say #define TEST1 10 We...
6
by: Nicola Mezzetti | last post by:
Greetings, I write to ask information about how to disable the preprocessor checks on macros when compiling with command line Borland C++ compiler. Waiting for a reply, i thank you all for the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.