[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3431.0. "Any plans for something like CONTROLASSIGN?" by GAAS::TSUK (Michael Tsuk) Tue Feb 04 1997 20:14

We've been moving from C to C++, and one of the things we miss
is the ability to enable the CONTROLASSIGN warning, to catch
bugs like this:

if (i = 1) {
 
when we meant

if (i == 1) {

We were surprised that this warning doesn't seem to be available
in DECC++.  Are there any plans to put it in?

				-Michael
T.RTitleUserPersonal
Name
DateLines
3431.1Coding suggestion, fwiw...DECC::SULLIVANJeff SullivanTue Feb 04 1997 21:0215
Not sure if this will help, but, I've read this suggestion and heard it preached
elsewhere...

Write the conditional with the constant on the left of the "=="

  if (1 = i) { // this is not what you meant and will error

instead of

  if (1 == i) { // this does what you meant


I generally don't follow it myself, but it's not a bad idea.

-Jeff
3431.2V6.0 will do something like thisDECCXX::MITCHELLTue Feb 04 1997 21:283
cxx: Warning: test.cxx, line 3: possible use of "=" where "==" was intended
        if (i = 1) j = 1;
------------^
3431.3Thanks!GAAS::TSUKMichael TsukWed Feb 05 1997 18:1519
>Write the conditional with the constant on the left of the "=="
>
>  if (1 = i) { // this is not what you meant and will error
>
>instead of
>
>  if (1 == i) { // this does what you meant

This works only if the thing on the left is a constant.  We'd still have
the problem if it were a variable.

>V6.0 will do something like this
>cxx: Warning: test.cxx, line 3: possible use of "=" where "==" was intended
>        if (i = 1) j = 1;
>------------^

Thanks, this is just perfect.  Now I just need to wait for V6.0...

				-Michael