> Almost all modern C/C++ compilers will flag that as a warning That may well be. I stand by my claim that it is a common source of errors.
I am not sure if z/OS XLC flags it. I am also not sure whether z/OS XLC is a modern C/C++ compiler. <g> The intentional use of = in a condition is a favorite of old-style "how few keystrokes can I use" C programmers, for example in the formulation if (myfile = fopen(...)) ... // executes code if fopen is successful Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of David Crayford Sent: Tuesday, March 29, 2022 7:49 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: PL/I question On Tue, 2022-03-29 at 15:10 -0700, Charles Mills wrote: > Well, while we are digressing ... > > There was discussion earlier of the use of the equal sign for assignment > versus comparison. > > I am going to guess that THE most common cause of C/C++ program errors is the > mis-use of = for comparison. (The comparison operator in C and C++ is ==.) In > C if you code > > if (foo = 3) bar = 5; > > Then the compiler generates code to assign 3 to foo, test the result (3) for > truth (not 0) and then execute the conditional statement. The above has the > same effect as Almost all modern C/C++ compilers will flag that as a warning. And there are options to promote warnings to errors. For example: ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN