Curious assignment behaviour

John Roth johnroth at ameritech.net
Wed Oct 10 11:30:23 EDT 2001


"Andrew Dalke" <dalke at dalkescientific.com> wrote in message
news:9q121p$aia$1 at slb0.atl.mindspring.net...
> Paul Rubin:
> >The thing is, it's just not a matter of MY immunities.  I've spent
> >plenty of time debugging other people's code too, and have encountered
> >all kinds of errors in both their code and mine.  The =/== mistake has
> >just been very rare in my experience.  Can it be that the Unix
> >compilers I use flag the error a lot of the time, so it gets fixed
> >quickly, while Windows compilers don't flag it, and you're mostly
> >using Windows compilers?
>
> You're kidding us, aren't you?  Or maybe you've only been programming
> for the last few years.  When I started with unix (IRIX 3.3 in 1990)
> it came with a K&R C compiler.  It didn't have any of this sort of
> checking.  That's why 'lint' was written.
>
> And you're saying you've never seen all the code that uses
>     if (22 == a)
> instead of
>     if (a == 22)
> just in case the '==' is accidently replaced with '='?  That's
> common enough to be mentioned as a joke in Q5.A. of
>   http://www.ddj.com/columns/stob/2001/0110vs001.htm
> ] When comparing variables with constants, write the constant
> ] first to avoid accidental assignment ie write
>
> GCC was the first unix compiler I saw which generated a warning
> for this problem.  That was about 4 or 5 years ago.  But trying
> some compilers I have access to (some old C compilers too :)
>
> > uname -a
> SunOS day 5.7 Generic sun4d sparc SUNW,SPARCserver-1000
> > cc -V
> ucbcc: SC3.0.1 13 Jul 1994
>   ...told you it was old :)
> >
> > cat > test.c
> main() {
>   int i = 0;
>   if (i = 1) {
>     printf("Hello.\n");
>   }
> }
> > cc test.c
> > ./a.out
> Hello.
> >
>
> With "WorkShop Compilers 5.0 98/12/15 C 5.0" on "SunOS 5.7"
> there is no warning.
>
> With "MIPSpro Compilers: Version 7.2.1" on IRIX 6.4 there
> *is* a warning.
>
> Don't currently have ready access to other compilers.

I believe that the AIX compiler I used on an IBM SP had that
warning. However, it was burried in so many other warnings and
non-sensical comments that most of us had it turned off. I did a
Perl script (this was before I knew about Python) to filter the
warnings to just those I had to deal with. It helped reliability
immensely.

John Roth
>
>                     Andrew
>                     dalke at dalkescientific.com
>
>
>





More information about the Python-list mailing list