473,288 Members | 1,771 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,288 software developers and data experts.

partial/selective Macro expansion scpp

Hi Ng,
i am looking for a method of expanding a macro while the rest of the
code remains untouched.

I have some code which does macro voodo / ifdef's which i would like to
strip and simplify.

The Faq pointed me to scpp but i could not compile it. the lex.c
generated by flex 2.5.4 is broken.

This problem occured also in 2004 in this group.
any Ideas where to get a working copy or how to compile it??

Regards,
Michael

-- snip --
It generates code using 'yyconst', which it doesn't declare anywhere
(presumably it's supposed to be defined as 'const').
It generates code using 'yy_cp' which likewise isn't (always)
declared (it's declared in some funcxtions but not in others).
May 5 '06 #1
7 3470
reppisch wrote:
Hi Ng,
i am looking for a method of expanding a macro while the rest of the
code remains untouched.

I have some code which does macro voodo / ifdef's which i would like to
strip and simplify.

The Faq pointed me to scpp but i could not compile it. the lex.c
generated by flex 2.5.4 is broken.

This problem occured also in 2004 in this group.
any Ideas where to get a working copy or how to compile it??


Here's a thought: Instead of providing a string of vague references and
expecting a solution to an unclear problem, why don't you explain
exactly what you are trying to accomplish and provide an example of
what you might have tried already. If you do that we might actually be
able to help.

Robert Gamble

May 5 '06 #2
reppisch wrote:
i am looking for a method of expanding a macro while the rest of the
code remains untouched.
Depending on your implementation (it's possible with GCC, for example)
and exactly what your situation is, it may be possible and feasible to
simply run the preprocessor on the source files in question.
It generates code using 'yyconst', which it doesn't declare anywhere
(presumably it's supposed to be defined as 'const').


<ot>It's been too long since I used (f)lex to give helpful advice here,
but I feel confident advising you to STFW and RTFM; the chances of flex
being genuinely broken are not high.</ot>

--
C. Benson Manica

May 5 '06 #3
>
Here's a thought: Instead of providing a string of vague references Btw: g$$gle news does not provide message-Ids (anymore).
and expecting a solution to an unclear problem, why don't you explain
exactly what you are trying to accomplish and provide an example of
what you might have tried already.

I'm sorry if i couldn't make my self more clear.
i'll try to show it in a sample.

a.h contains some macros like
--------
#define LOG(a,b,c,d) FancyLogFunction(__LINE__,__FILE__,a,c,d,b);

b.h contains some obfuscating voodoo like:
--------
#ifdef VOODO
#define VOODOOLOG(a,b) LOG(a,b,"const",strlen(b))
#else
#define VOODOOLOG(a,b) /* nothing */
#endif

c.c:
--------
#include "a.h"
#include "b.h"

....
VOODOLOG("this","that");
....
now i want to siplify things
and get some source like this:

c-processed.c
--------
#include "a.h"
#include "b.h"

....
LOG("this","that","const",strlen("that"));
....

So i want to have the file c.c *partially* preprocessed by expanding
*only* the VOODOLOG Macro.

I tried to do this with scpp but it does not compile on "modern" systems
since it produces a syntactically wrong output from flex while in the
make- Process.

By using the -E option on gcc i would end up in a fully dereferenced
c-file which is not what i want.

Doing the expansion manually is not an option since this only a very
simple sample and chaces are good to do it wrong somewhere.

May 7 '06 #4
michi wrote:

Here's a thought: Instead of providing a string of vague references Btw: g$$gle news does not provide message-Ids (anymore).
and
expecting a solution to an unclear problem, why don't you explain
exactly what you are trying to accomplish and provide an example of
what you might have tried already.

I'm sorry if i couldn't make my self more clear.
i'll try to show it in a sample.

a.h contains some macros like
--------
#define LOG(a,b,c,d) FancyLogFunction(__LINE__,__FILE__,a,c,d,b);

b.h contains some obfuscating voodoo like:
--------
#ifdef VOODO
#define VOODOOLOG(a,b) LOG(a,b,"const",strlen(b))
#else
#define VOODOOLOG(a,b) /* nothing */
#endif

c.c:
--------
#include "a.h"
#include "b.h"

...
VOODOLOG("this","that");


I assume that should be VOODOOLOG and that VOODO has been defined
before b.h was included.
...
now i want to siplify things
and get some source like this:

c-processed.c
--------
#include "a.h"
#include "b.h"

...
LOG("this","that","const",strlen("that"));
...

So i want to have the file c.c *partially* preprocessed by expanding
*only* the VOODOLOG Macro.
Either don't include a.h or undefine LOG somewhere before the VOODOLOG
macro invocation if you don't want the macro expanded a second time.
Why do you want to do this, what are you trying to accomplish? Why do
you even have the macro in a.h if you do not want to use it?
I tried to do this with scpp but it does not compile on "modern" systems
since it produces a syntactically wrong output from flex while in the
make- Process.

By using the -E option on gcc i would end up in a fully dereferenced
c-file which is not what i want.
Right, most compilers don't have an option to do "partial
preprocessing".
Doing the expansion manually is not an option since this only a very
simple sample and chaces are good to do it wrong somewhere.


Robert Gamble

May 7 '06 #5
michi <sp**@reppisch.de> writes:
Here's a thought: Instead of providing a string of vague references

Btw: g$$gle news does not provide message-Ids (anymore).


If you'd spend 30 seconds looking, you'd see that it does. You
can find an article with a given message-id with the advanced
search feature. You can see the message-id of an article with
Show Original.
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
May 7 '06 #6
got it
Show Original.

May 7 '06 #7
Robert Gamble schrieb:

I assume that should be VOODOOLOG and that VOODO has been defined
before b.h was included. right.

So i want to have the file c.c *partially* preprocessed by expanding
*only* the VOODOLOG Macro.

Either don't include a.h
or undefine LOG somewhere before the VOODOLOG
macro invocation if you don't want the macro expanded a second time.

which would prevent expansion of the LOG-macro but the rest of the code
*would* be expanded as far as possible.

Why do you want to do this, what are you trying to accomplish? Why do
you even have the macro in a.h if you do not want to use it?

I'd like to use LOG instead of VOODOLOG to make the code more
transparent. This was only a silly sample.

The macro-framework has grown behind the scenes makes the code
unreadable, difficult to debug and allmost impossible to analyze with
tools like sourcenavigator or doxygen.

Do you think it's a good idea to have macors around like
#define FCT_TRC(rc,n,p,x) FCT_TRC_TXT(rc,n,p,x,"")
#define FCT_TRC_TXT(rc,n,p,x,t) { if(((rc)=n p)<0) { LOG_L(#n,rc,t);
x } }
#define LOG_L(f,rc,trc) LOG((C1, C2, C3, (int)(rc), f, trc))

and end up in "function" calls like
FKT_TRC(iRet, someFunction, (arg1, arg2), goto EMERGENCY_EXIT;);
?

I call that preprocessor abuse.
May 7 '06 #8

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
3
by: Caleb Hattingh | last post by:
Hi Here is a script I want to be able to write (explanation appears after): *** start of script *** import MyCustomMacroLib # This does the magic I would like help for. # This is not...
6
by: max(01)* | last post by:
hi. i want to examine preprocessed source which only has certain macros expanded, for example i would like to have: #include <stdio.h> #include "other.c" int main() { ... }
5
by: Patrick Kowalzick | last post by:
Hi all, Is this valid? I do not find the case in the standard: void foo( int ) {} #define FOO foo int main() {
4
by: ImOk | last post by:
I come from the Visual Foxpro world, which is one reason I love PHP. VFP is a scripting type language with macro substitution abilities similar to PHP. Besides the regular expansion I can do...
2
by: talkaboutquality | last post by:
Need to define a macro as, say, #ifdef NEED_FUNCTION foo(x) #else #endif
6
by: jason | last post by:
Hi, I learned my lesson about passing pointers, but now I have a question about macros. Why does the function work and the MACRO which is doing the same thing on the surface, does not work in...
5
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing...
6
by: Bing | last post by:
Hi folks, Is there a way to define a macro that may contain #include directive in its body. If I just put the "#include", it gives error C2162: "expected macro formal parameter" since here I am...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.