Style question: (5 == x) or (x == 5)

A

Alan Balmer

- If you preceive any intuitive difference its because you have a
defective brain; you should be banned from programming. Seriously.

Too bad - it's a few decades too late to ban me, my defective brain,
and the millions of lines of quality code I've written, so I'll just
say "You're full of it." Seriously.
 
R

RoSsIaCrIiLoIA

Darrell Grainger wrote:
... snip ...
I use if( x==12 || 5<=x ) etc
It certainly is a religious issue, and I am on the (5 == x) side.
The first time it saves you a long bug hunt it has paid for

Is it possible that this NG 'regulars' have a
"space" "(" ")" "=" "==" combination in if statement that
allows this kind of error?

I don't remember *one* error in this subject in my code and I have
uninhabited the warning on it too.
 
M

Mark McIntyre

I'm glad I don't have to use your code.

Actually its a fair comment - the MS headers churn out zillions of warnings
if you have warning level at 4. I compromise by modularising my code and
compiling the iso parts at level 4 and teh ms parts at level 3.
 
G

Guillaume

I guess Microsoft embraces the "Trust the Programmer" motto of C. }:-0

Nope, I don't believe so, not for one second even.

It's just that Microsoft hasn't cared about C for years.
I'm not sure their C++ compilers are much better; probably in the same
vein. But they don't care much about C++ anymore either.

They themselves never use C anymore - that is, outside of their OS
development. But who knows if they are not actually using Intel's
C compiler for their OS needs... <evil look>
 
S

Stephen Sprunk

Mitchell said:
Pardon my ignorance! Can I know how this works?

(0,x) is not a modifiable lvalue, so translation will fail if you
accidentally type "=" instead of "==".

However, as an expression (0,x) simply returns x, so the test works properly
when "==" is used.

S
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top