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

Macro substitutions

I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?

Dec 22 '05 #1
7 1325
James S. Singleton wrote:
I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?

Nope.
The preprocessor is dumb*. It works purely by textual substitution.

HTH,
--ag

* - By `dumb' I refer to its level of sophistication. It knows about
tokens, but not anything else about how C works.

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Dec 22 '05 #2


James S. Singleton wrote On 12/22/05 14:48,:
I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;


No. You could, if you wish, write

x = h->(ABC)(w);

.... but it would probably prevent confusion if you
made a practice of using different names for different
things.

--
Er*********@sun.com

Dec 22 '05 #3
James S. Singleton wrote:

I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?


Yes.
Precede the lines that you want left alone with

#undef ABC(x)

and then redefine ABC(x), after.

--
pete
Dec 22 '05 #4

pete wrote:
James S. Singleton wrote:

I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?


Yes.
Precede the lines that you want left alone with

#undef ABC(x)

and then redefine ABC(x), after.


Bit of a kludge isn't it? It also means that anyone using ABC had
better know about this quirk.

Dec 23 '05 #5

James S. Singleton schreef:
I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?


Are you sure your problem is with the preprocessor? I do not know you
application, of course, but when you need this kind of "exceptions", it
makes me think you are suffering from a design-flaw.
It's much better to adress that than introduce some of the kludges
suggested elsewhere in this thread, which will surely end up in
unmaitainable code.

1. Why do you need such an exception?
2. Is employing the same macro in both cases neccesary? If so, why?
3. Can't it be solved differently? You (almost *) ) _always_ have
multiple alternatives to code an algorithm. Choose one that suits you
_and_ the language.

*) I can't think of an example in which there is only one way, but that
does not say there isn't one.

Dec 23 '05 #6
"James S. Singleton" <pt***@excite.com> wrote:
Is it possible to get the preprocessor to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?


It probably isn't, in any sane way, but if you discover a workaround,
let me beg of you, for the sake of your maintenance programmers, your
debuggers, and your documentation writers, please, _PLEASE_ don't.

Richard
Dec 27 '05 #7
gooch wrote:

pete wrote:
James S. Singleton wrote:

I have the following macro:

#define ABC(x) f((x) + 1)

Is it possible to get the preprocessor
to replace lines like

x = g(y) + ABC(z/3) ;

with

x = g(y) + f((z/3) + 1) ;

but leave lines like

x = h->ABC(w) ;

alone?


Yes.
Precede the lines that you want left alone with

#undef ABC(x)

and then redefine ABC(x), after.


Bit of a kludge isn't it? It also means that anyone using ABC had
better know about this quirk.


Yes.

--
pete
Jan 5 '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...
1
by: Tony Eva | last post by:
The spinbox widget in Tk 8.4 has an option to allow a command to be specified that is invoked when either the up or down buttons of the spinbox are pressed, as in: ... self.sb =...
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...
21
by: Eric | last post by:
Hello all, I've got this line of given code (cannot change this; wizard-generated, but value may change someday): #define IDB_BUTTON 225 Somewhere in the code I found /...
27
by: Yan | last post by:
A lot of times when reading open software, i come across macros that are defined as follows: #define CALL_FUNCS(x) \ do { \ func1(x); \ func2(x); \ func3(x); \ } while (0);
8
by: David | last post by:
Hi, I am using header file for driver so Can I define macro to call Kernel function ? What are the generatl rules for defining macro. - David
14
by: Malcolm | last post by:
Hi, I have the following which fails with "disagreement in number of macro arguments" when compiling with Imagecraft ICCAVR. Has anyone got any ideas - its not vital but would make the code a...
8
by: abhishek | last post by:
>>a,b=3,4 7 Now I want to evaluate y by substituting for the evaluated value of x. eval(y) will try to add "a+b" to 3 and return an error. I could do this, 10 but this becomes unwieldy if I...
8
by: Shilpa | last post by:
Hi Can anyone guide me by providing me the code ,for the following requirement: how to write a macro for a 16 bit processor that returns the calculated seconds of a year assuming 365 days in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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:
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.