C's syntax
Alex Martelli
aleaxit at yahoo.com
Mon Oct 23 12:04:04 EDT 2000
"Erik Max Francis" <max at alcyone.com> wrote in message
news:39F45B51.320AA63F at alcyone.com...
> Olivier Dagenais wrote:
>
> > To get around this, we were taught to put the constant on the other
> > side, so
> > that if we forgot an '=', we would get a compiler error:
> >
> > if ( 0 = a ) /* is bad */
> > if ( 0 == a ) /* is good */
>
> Which is a common coding style, but is really unnecessary. Any
> reasonable compiler will warn against statements such as `if (a = 0)
Visual C++ may not be "reasonable", but it's still one of the most
widespread on the market, and does NOT give this warning at normal
warning-levels (and the system header files spew oodles & oodles of
warnings if you try to enable warnins at pedantic-level, so one
does not normally use that).
If I recall correctly (it _was_ a while ago), vendor-supplied C
compilers on many Unix systems did not supply that warning either.
> ...'. Simply look at the warnings, there's no reason to write things in
> an unnatural order.
It's a good coding habit to get into, to ensure that particular
slip will be caught by any standard compiler, rather than relying
on specific warning-relater features that NOT all compilers have.
Alex
More information about the Python-list
mailing list