449,284 Members | 1,246 Online
Need help? Post your question and get tips & solutions from a community of 449,284 IT Pros & Developers. It's quick & easy.

# Tricky macro manipulation

 P: n/a Does anyone know of a way to manipulate a macro list to remove either the beginning or the end element? I.e. Given: #define ELEMENTS EL(1) EL(2) EL(3) Is there any manipulation to get just EL(1) EL(2) out of ELEMENTS? Thanks for your help. Adrian -- __________________________________________________ ___________________ \/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/ \ _---_ Q. What are you doing here? _---_ / \ / | A. Just surf'n the net, teaching and | \ / \__/___\___ learning, learning and teaching. You?_____/___\__/ \/______[blog:__http://adrians-musings.blogspot.com/]______\/ Mar 23 '07 #1
6 Replies

 P: n/a On Mar 23, 11:03 am, Adrian Hawryluk

 P: n/a Adrian Hawryluk wrote: Does anyone know of a way to manipulate a macro list to remove either the beginning or the end element? I.e. Given: #define ELEMENTS EL(1) EL(2) EL(3) Is there any manipulation to get just EL(1) EL(2) out of ELEMENTS? Thanks for your help. Adrian The real question is why you need do something like that? How about: #define ELEMENTS EL(1) EL(2) EL(3) #define FIRST_2_ELEMENTS EL(1) EL(2) Mar 23 '07 #3

 P: n/a Fei Liu wrote: Adrian Hawryluk wrote: >Does anyone know of a way to manipulate a macro list to remove eitherthe beginning or the end element? I.e. Given: #define ELEMENTS EL(1) EL(2) EL(3)Is there any manipulation to get just EL(1) EL(2) out of ELEMENTS?Thanks for your help. Adrian The real question is why you need do something like that? How about: #define ELEMENTS EL(1) EL(2) EL(3) #define FIRST_2_ELEMENTS EL(1) EL(2) Wouldn't it be better reversed? #define FIRST_2_ELEMENTS EL(1) EL(2) #define ELEMENTS FIRST_2_ELEMENTS EL(3) Mar 23 '07 #4

 P: n/a Fei Liu wrote: Adrian Hawryluk wrote: >Does anyone know of a way to manipulate a macro list to remove eitherthe beginning or the end element? I.e. Given: #define ELEMENTS EL(1) EL(2) EL(3)Is there any manipulation to get just EL(1) EL(2) out of ELEMENTS?Thanks for your help. Adrian The real question is why you need do something like that? How about: #define ELEMENTS EL(1) EL(2) EL(3) #define FIRST_2_ELEMENTS EL(1) EL(2) The reason is for writing recursively defined template code. mlimber gave me what I needed. The boost preprocessor library was something that I was going to have to (in some capacity) implement if I didn't know about it. Though I was /almost/ ok without it, this will simplify things considerably. Thanks all, Adrian -- __________________________________________________ ___________________ \/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/ \ _---_ Q. What are you doing here? _---_ / \ / | A. Just surf'n the net, teaching and | \ / \__/___\___ learning, learning and teaching. You?_____/___\__/ \/______[blog:__http://adrians-musings.blogspot.com/]______\/ Mar 23 '07 #5

 P: n/a "Adrian Hawryluk" #define PLACE_X(x)x #define PLACE(x)PLACE_X(x) #define QUOTE_X(x)#x #define QUOTE(x)QUOTE_X(x) #define STRIPL_X(x, y)PLACE(x) #define STRIPL(x)PLACE(STRIPL_X)x #define STRIPR_X(x, y)PLACE(y) #define STRIPR(x)PLACE(STRIPR_X)x #define MYLIST() (node1, (node2, (node3, null))) #define MYLIST_X(l)\ STRIPL(l)STRIPL(STRIPR(l)) /*** Static API Declaration _________________________________***/ static char prompt_getchar(char const*); #define promptexit_getchar(vzmp_buf)\ ((int)prompt_getchar((vzmp_buf))) /*** Static API Definition _________________________________***/ /* Entry -------------------*/ int main(void) { { printf("%s\n", QUOTE(MYLIST())); printf("%s\n", QUOTE(MYLIST_X(MYLIST()))); } return promptexit_getchar("\n\n--- press

 P: n/a Chris Thomasson wrote: "Adrian Hawryluk" Does anyone know of a way to manipulate a macro list to remove either thebeginning or the end element? I.e. Given: #define ELEMENTS EL(1) EL(2) EL(3)Is there any manipulation to get just EL(1) EL(2) out of ELEMENTS? [...] #include #define PLACE_X(x)x #define PLACE(x)PLACE_X(x) #define QUOTE_X(x)#x #define QUOTE(x)QUOTE_X(x) #define STRIPL_X(x, y)PLACE(x) #define STRIPL(x)PLACE(STRIPL_X)x #define STRIPR_X(x, y)PLACE(y) #define STRIPR(x)PLACE(STRIPR_X)x #define MYLIST() (node1, (node2, (node3, null))) #define MYLIST_X(l)\ STRIPL(l)STRIPL(STRIPR(l)) /*** Static API Declaration _________________________________***/ static char prompt_getchar(char const*); #define promptexit_getchar(vzmp_buf)\ ((int)prompt_getchar((vzmp_buf))) /*** Static API Definition _________________________________***/ /* Entry -------------------*/ int main(void) { { printf("%s\n", QUOTE(MYLIST())); printf("%s\n", QUOTE(MYLIST_X(MYLIST()))); } return promptexit_getchar("\n\n--- press

### This discussion thread is closed

Replies have been disabled for this discussion.