When do you use "if ( a = b )"? (was Re: Funny mistake)

Michael Henning michi at ptcburp.ptcbu.oz.au
Wed Mar 27 09:35:55 AEST 1991


darren at revcan.UUCP (Darren Morbey) writes:

>Just as a suggestion, what about:
>     #define EQU(l,r) ((l)==(r)) /*...*/ if( EQU(a,b) )
>I realize this is rather messy, because it
>"contribute[s] nothing to the readability of the code." (Mr. Henning)
>It does make the equality different from the assignment without violating
>"#define should _never_ be used to replace existing tokens." (Mr. Houghton)

If you realize that it is rather messy, why do it ?  When someone else, who
is not familiar with your coding style, gets to see this, he most likely
won't know immediately what EQU means, and he will have to go hunting for
the macro definition (not always easy if there are a lot of source and
header files). What is the point of taking an operator that is already
defined in the language and making it look like something else ?

>Pardon me for asking, but please define "obfuscation."

Your EQU *is* obfuscation, because it replaces something that everyone
knows about and can understand (==) with something that no one knows
about (EQU).

>P.S.  I would find it useful to #define NOT(a) !(a),
>      #define COMPL(a) ~(a), and #define XOR(a,b) ((a)^(b)).
>      I have trouble remembering the use of the tilde and
>      circumflex.  Again, only a suggestion.

If you have trouble remembering !, ~ and ^, then learn them, don't #define
them to something else that *you* find easier, but many other people will
only find annoying.

						Michi.
-- 
      -m------- Michael Henning			+61 75 950255
    ---mmm----- Pyramid Technology		+61 75 522475 FAX
  -----mmmmm--- Research Park, Bond University	michi at ptcburp.ptcbu.oz.au
-------mmmmmmm- Gold Coast, Q 4229, AUSTRALIA	uunet!munnari!ptcburp.oz!michi



More information about the Comp.lang.c mailing list