One of the things that I liked about Algol was that "=" was always a comparison 
operator; assignment was ":=". But even in PL/I that particular error is 
impossible: the "=" in "IF foo=bar" can never be interpreted as assignment.


--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3

________________________________________
From: IBM Mainframe Discussion List <[email protected]> on behalf of Tom 
Marchant <[email protected]>
Sent: Monday, July 15, 2019 4:44 PM
To: [email protected]
Subject: Re: Where put the notional constant in a condition (Was RE: JCL COND 
Parameter)

On Mon, 15 Jul 2019 13:30:51 -0700, Charles Mills wrote:

>Some C programmers are fond of if (7 == foo) rather than the more conventional 
>if (foo == 7) because if one gets in the habit of doing so and then 
>accidentally codes if (7 = foo) one gets a compile error rather than 
>unexpected behavior.
>
>For those not familiar with C, foo == 7 is a relational expression, foo = 7 is 
>an assignment, and if (foo = 7) ... compiles as though one had coded
>
>foo = 7; if (foo != 0) /* which will be true of course */ ...
>
>which is not at all what was presumably intended.
>
>7 = foo is always a compile-time error; you can't assign a variable to a 
>constant.

It's one of the things that I don't like about C.
While you can code if 7 = foo and the compiler will catch your error, there is 
nothing
you can do to protect yourself against the mistake of if foo = bar.

--
Tom Marchant

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to