TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Paul Person
from: hugo landsman
date: 1996-02-01 02:18:36
subject: C errors

hi Paul,

 * Re:  C-style soapbox
   to   John Poltorak
 PP> Fourth, the warnings about "=" instead of "=="
are there because a
 PP> common  error in conditions is to use "=" when
"==" is meant: if(A=B)
 PP> versus  if(A==B). The first assigns the value of B to A and uses the
 PP> value of B for  the test, the second compares the values of A and B
 PP> and returns a value  based on whether they are the same or not.
 PP> *These* are the warnings you  want to look at to try to determine
 PP> whether an assignment was intended or  not. (An assignment is often
 PP> intended in forms like if(A=f()), where  function f() returns a value
 PP> which is to be tested for success).

It is bad style: you realy should write 'if (0!=(A=B))' or 'if
(0!=(A=f()))' where that is what you mean, not only to make compilers
happy, but the people succeding you (that's you yourself a year later) too.
 Readability, and thus maintainability, code rules prescribe explicit tests
of assignment results.  Don't use compiler(-switche)s that don't warn about
such constructs. 

regards,
         hugo (back to our regular OS/2 schedule from this C_ECHO excursion)
* Origin: huug{at}telebyte.nl (2:283/608.5)
SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 283/608 2801/201 28/777 2/777 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.