Alternatives to #define?

  • Thread starter Carl Ribbegaardh
  • Start date
A

Alf P. Steinbach

* Rolf Magnus:
No, I mean what you gain compared to just:

#define DO_STUFF() { doThis(); doThat(); }

Uhm, see my reply to Rob Williscroft. I was wrong. And the extreme
irony is that I've always used do-while for such things precisely
because a simple block won't do wrt. semicolon syntax, and done my best
to teach that technique to others (since you can read Norwegian as well
as C++ code I can offer an example of such teaching, namely the XASSERT
macro in <url: http://home.no.net/dubjai/03/index.html#cpputil>,
presumably some Googling on newsgroup posting would give more examples).
 
C

Carl Ribbegaardh

Mark A. Gibbs said:
for. :)

thank you, and don't worry, i was aware i was replying two steps removed
when i was harping about the dangers of macros. sorry if i gave the
impression otherwise.

mark

One more question on the subject:

Why is (for example) SUCCEEDED and FAILED (in winerror.h) implemented as
macros?
...and other stuff that's common like SAFE_DELETE and so on...

Is it just done by habit, or are there any other reason for not using inline
functions?

:)
/Carl
 
M

Mike Smith

Robbie said:
I actually like that. Simple, direct, ALWAYS inlined.

It's dangerous, though. What if you have code like:

if (condition)
DO_STUFF
else
do_something_else();

This won't expand properly. You should write the macro as:

#define DO_STUFF {doThis(); doThat();}

but IMO using an inlined function would be better.
 
J

Jay Nabonne

One more question on the subject:

Why is (for example) SUCCEEDED and FAILED (in winerror.h) implemented as
macros?
..and other stuff that's common like SAFE_DELETE and so on...

Is it just done by habit, or are there any other reason for not using inline
functions?

The standard windows headers can be used in either C or C++ programs. And
inline functions are a C++-only nicety...

- Jay
 
R

Rolf Magnus

Jay said:
The standard windows headers can be used in either C or C++ programs.
And inline functions are a C++-only nicety...

That's not true. ISO C has been knowing the inline keyword for 5 years
now, and many C compilers have been supporting it for a much longer
time. The windows headers have never been ISO compliant anyway, so they
could have used inline, too.
 
J

Jay Nabonne

That's not true. ISO C has been knowing the inline keyword for 5 years
now, and many C compilers have been supporting it for a much longer
time. The windows headers have never been ISO compliant anyway, so they
could have used inline, too.

I had a feeling someone would object to that.

How about this replacement for my last line then: at the time that the
Windows header files were developed (> 5 years ago), C compilers (in
particular the Microsoft C compiler) didn't support inline functions.

Does that sit well enough? :)

- Jay
 
C

Carl Ribbegaardh

Jay Nabonne said:
I had a feeling someone would object to that.

How about this replacement for my last line then: at the time that the
Windows header files were developed (> 5 years ago), C compilers (in
particular the Microsoft C compiler) didn't support inline functions.

Does that sit well enough? :)

- Jay

Now I understand better why the API's looks like they do. Thanks a lot! :-D

/Carl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top