473,399 Members | 2,774 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,399 software developers and data experts.

#redefine preprocessor macro statement.

Hi All,

Is there a way to create a macro called #redefine that will allow
redefinition without having to use #ifdef/#undef

For example, I'd like to do something like this :

#define THING "apple"
... code

#redefine THING "banana"
... code

#redefine THING "orange"
... code
Instead of :

#define THING "apple"
... code

#undef THING
#define THING "banana"
... code

#undef THING
#define THING "orange"
... code


Jun 27 '08 #1
3 18696
On Apr 14, 1:00*pm, Ernie.Pasv...@cggveritas.com wrote:
Hi All,

Is there a way to create a macro called *#redefine that will allow
redefinition without having to use #ifdef/#undef

For example, *I'd like to do something like this :

* * #define THING *"apple"
* * ... code

* * #redefine THING "banana"
* * ... code

* * #redefine THING "orange"
* * ... code

Instead of :

* * #define THING *"apple"
* * ... code

* *#undef THING
* *#define THING "banana"
* * ... code

* *#undef THING
* *#define THING "orange"
* *... code
void isolating_function(char *thing)
{
/* Do stuff here */
}
isolating_function("orange");
isolating_function("banana");
isolating_function("apple");

I think that it is good that you cannot do what you want to do. It is
trouble waiting to happen.
Jun 27 '08 #2
On Apr 14, 4:00*pm, Ernie.Pasv...@cggveritas.com wrote:
Hi All,

Is there a way to create a macro called *#redefine that will allow
redefinition without having to use #ifdef/#undef

For example, *I'd like to do something like this :

* * #define THING *"apple"
* * ... code

* * #redefine THING "banana"
* * ... code

* * #redefine THING "orange"
* * ... code
just change the #redefine's to #define's

>
Instead of :

* * #define THING *"apple"
* * ... code

* *#undef THING
* *#define THING "banana"
* * ... code

* *#undef THING
* *#define THING "orange"
* *... code


You don't need the #undef before reusing the #define.
Jun 27 '08 #3
Kenneth Bull <ke**********@gmail.comwrites:
On Apr 14, 4:00*pm, Ernie.Pasv...@cggveritas.com wrote:
>Is there a way to create a macro called *#redefine that will allow
redefinition without having to use #ifdef/#undef

For example, *I'd like to do something like this :

* * #define THING *"apple"
* * ... code

* * #redefine THING "banana"
* * ... code

* * #redefine THING "orange"
* * ... code
No, there isn't. A macro expansion cannot include preprocessor
directives.
just change the #redefine's to #define's
[...]
You don't need the #undef before reusing the #define.
Yes, you do. C99 6.10.3p2 says:

An identifier currently defined as an object-like macro shall not
be redefined by another #define preprocessing directive unless the
second definition is an object-like macro definition and the two
replacement lists are identical.

followed by similar wording for function-like macros.

I see this was cross-posted to comp.lang.c and comp.lang.c++. I
assume the rules for C++ are similar, but I'm not certain. It's
better to post to the newsgroup that covers the language you're
actually using.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #4

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

Similar topics

19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
3
by: Charlie Zender | last post by:
Hi, I want to have a CPP macro that tests the value of a token and returns the string "No" if the token is undefined (or 0) and returns "Yes" if the token is defined (non-zero). Then I can...
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? ...
3
by: songie D | last post by:
would it be possible to sort of engineer some sort of preprocessor macro that does a 'for' loop. i.e. for where you would normally use a normal for loop, but when it is known ay compile time whay...
3
by: Ernie.Pasveer | last post by:
Hi All, Is there a way to create a macro called #redefine that will allow redefinition without having to use #ifdef/#undef For example, I'd like to do something like this : #define THING ...
3
by: Default User | last post by:
I've never really done too much stuff with macros. I have a program here where an target server address is automatically generated from WSDL. For testing, I want to use a localhost address. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.