On Fri, Feb 18, 2005 at 11:29:09AM +0000, Liam Bedford wrote:
> | No, It certainly is not. And even if it was, it certainly wouldn't be
> | equivalent to:
> | if (if(x==y) return 1; else return 0;)
> Am I missing something?
>> x == y is not the same as x != y
>> no matter how much syntactic preprocessor sugar you add.
Actually, that part isn't really the big problem :) If Brian was
writing an inline function, he'd almost be right:
inline int ISNOT(x, y)
if (x == y)
Would be close, though he'd have to be usign a modern C variant which
supports inline functions. Still, as you correctly point out, if you
were to use this as:
if (ISNOT(x, y))
well then really it needs to return 1 when x is not equal to y. So
there's problem one, he's got the returns the wrong way round.
Now, on to the really serious problems. Preproccesor macro arnt inline
functions, they get put in-place in the code, like a fancy sed
operation. This has a few implication which Brian obviously doesn't know
about. Firstly, if you use a return statement, well you're going to
return out of the current function. And since he contains such satements
within his macro, then it isn't something valid to put within the walls
of an if statements condition.
"if (if(x==y) return 1; else return 0;)"
Isn't even valid C, it will get you nowhere. And even if say you
were to use his ISNOT in isolation, it becomes almost like assert(),
would be an assertion that would exit the current function with a value
of 0 if they are equal and 1 if they are not.
And lastly, the really subtle thing that Brian doesn't get. Brackets
really matter. Even with my macro, these two:
#define ISNOT(x, y) (x != y)
#define ISNOT(x, y) ((x) != (y))
Are not quite the same thing. What if I did:
if (ISNOT(x && y, z))
For example. All in all, I think there are 5 seperate ways in which
Brians one-line ISNOT operator is entirely broken. It's almost one of
the best arguments in favour of software patents I've ever seen.
Colm MacCárthaigh Public Key: colm+pgp at stdlib.net
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!