Re: conditional operator again




Markus Moll wrote:
a) You lose some type-safety.
b) With macros, you should _always_ enclose the parameters in parenthesis:
#define func(flag, ptr) (( (flag) == 1 || (flag) == 2) ...
c) Your parameters may be evaluated more than once, which might lead to
problems (especially as you call your macro "func"):
ptr2 = func(++flag, ptr); // undefined
d) It's terrible to read.

All in all, don't do it.


Thanks for your suggestions. Just to clarify, nowhere in my code func()
will be
called as
ptr = func(++flag, ptr). In fact, flag is not a integer variable. It is
always called as
ptr = func(HASH_DEF_VALUE, ptr). where HASH_DEF_VALUE may be 1, 2 or
3.
And, also *ptr will never be NULL.

.



Relevant Pages