Connecting Tech Pros Worldwide Help | Site Map

Tricky macro manipulation

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 23rd, 2007, 03:05 PM
Adrian Hawryluk
Guest
 
Posts: n/a
Default Tricky macro manipulation

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/]______\/

  #2  
Old March 23rd, 2007, 03:25 PM
mlimber
Guest
 
Posts: n/a
Default Re: Tricky macro manipulation

On Mar 23, 11:03 am, Adrian Hawryluk <adrian.hawryluk-at-
gmail....@nospam.comwrote:
Quote:
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?
Not that I'm aware of, but if you are willing to use the Boost
Preprocessor library, it has tuples and lists and algos that could
accomplish something similar but different.

Cheers! --M

  #3  
Old March 23rd, 2007, 06:35 PM
Fei Liu
Guest
 
Posts: n/a
Default Re: Tricky macro manipulation

Adrian Hawryluk wrote:
Quote:
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)
  #4  
Old March 23rd, 2007, 07:35 PM
red floyd
Guest
 
Posts: n/a
Default Re: Tricky macro manipulation

Fei Liu wrote:
Quote:
Adrian Hawryluk wrote:
Quote:
>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)
Wouldn't it be better reversed?

#define FIRST_2_ELEMENTS EL(1) EL(2)
#define ELEMENTS FIRST_2_ELEMENTS EL(3)

  #5  
Old March 23rd, 2007, 10:05 PM
Adrian Hawryluk
Guest
 
Posts: n/a
Default Re: Tricky macro manipulation

Fei Liu wrote:
Quote:
Adrian Hawryluk wrote:
Quote:
>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)
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/]______\/
  #6  
Old March 24th, 2007, 02:15 AM
Chris Thomasson
Guest
 
Posts: n/a
Default Re: Tricky macro manipulation


"Adrian Hawryluk" <adrian.hawryluk-at-gmail.com@nospam.comwrote in message
news:u%RMh.3219$6z3.553@edtnps82...
Quote:
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?
[...]

#include <cstdio>

#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 <ENTERto exit ---\n");
}

/* Displays a prompt and waits on getchar
-------------------*/
char prompt_getchar(char const *buf) {
printf("%s", buf);
return getchar();
}



Does that work for you?


  #7  
Old March 24th, 2007, 01:15 PM
Adrian Hawryluk
Guest
 
Posts: n/a
Default Re: Tricky macro manipulation

Chris Thomasson wrote:
Quote:
"Adrian Hawryluk" <adrian.hawryluk-at-gmail.com@nospam.comwrote in message
news:u%RMh.3219$6z3.553@edtnps82...
Quote:
>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?
[...]
>
#include <cstdio>
>
#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 <ENTERto exit ---\n");
}
>
/* Displays a prompt and waits on getchar
-------------------*/
char prompt_getchar(char const *buf) {
printf("%s", buf);
return getchar();
}
>
>
>
Does that work for you?
>
>
Interesting, but that gives:
////////////////////////////////////////////////////////////////////////
static char prompt_getchar(char const*);
//[...]
int main(void) {
{
printf("%s\n", "(node1, (node2, (node3, null)))");

printf("%s\n", "node1node2");

} return ((int)prompt_getchar(("\n\n--- press <ENTERto exit ---\n")));
}



char prompt_getchar(char const *buf) {
printf("%s", buf);
return getchar();
}
////////////////////////////////////////////////////////////////////////
Which shows that it is not recursively callable.

I think that I will use Boost's Meta Programming Language (MPL). The
way I was coding, I was heading in that direction (using a self included
file with macros to generate essentially the same code on separate
levels) anyway. Though Boost's MPL has now put my programming skills on
a whole new level. For me to generate that library to its current
degree would have taken me years if not decades (probably took them that
long too ;)).

Thanks anyway though.

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/]______\/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.