Old-fashioned assignment operators (was Re: braces

D.Rorke der at sfmag.UUCP
Thu Dec 29 03:31:20 AEST 1988


>   The question I have is, what exactly *is* the correct interpretation of
> x=-y in modern C? As mentioned before, the Encore cc interprets it as
> augmented assignment.  The compiler I use on my PC interprets it as assigning
> -y to x.  Which interpretation is right? What does the ANSI C standard say
> about this? 

>From Appendix C of the Second Edition of K & R:

	"The old assignment operators like =+ are truly gone."


>    Of course, the existence of compilers that interpret this line differently
> means that if you want your code to be portable, you *must* include proper
> spaces; if you want to assign -y to x, you must say "x = -y" if you want
> your code to work everywhere.  

In this case the use of spaces is somewhat of a moot issue.
Even if all compilers interpreted x=-y correctly (assign -y to x),
using x = -y would still be preferable because the spacing enhances
readability (my two cents worth on coding style).

Of course, the existence of old, brain-dead compilers means that if you
want your code to work EVERYWHERE you have to do lots of things
like avoid the use of "enum" and "void", and treat only the first
eight characters of an internal name as significant.

In general I'm in favor of using useful features of the language which
most compilers have supported for years.  I think extending the definition
of portability to mean "must use only the subset of features supported by
every old compiler in existence" is a mistake.  Let the person compiling
the code worry about having a 20th century compiler.  Of course there are
exceptions to this;  for instance you may have a specific customer that can't
be expected to get a modern compiler because none exists for obscure
architecture X that he is using.

ANSI C will make life much easier in this respect.  I am glad to see that
the committee had the courage to require support for certain features of
the language that are not currently universally supported.  This will
encourage the development of ANSI conformant code (since the standard
doesn't prevent you from using useful new features) and will therefore
actually enhance portability.
The is in contrast to other standards efforts, particularly in the 
operating systems area, which standardize on the least common denominator
of existing implementations, thereby creating a standard which doesn't
provide enough functionality to write many useful applications.


>    Finally, I question why this business of checking for old-fashioned 
> assignment operators is still in Unix C compilers.  After all, V7 came
> out around 10 years ago!  Does anyone really have around any code that hasn't
> been converted to the new syntax by *now*?  

In some cases the compiler doing the checking may be rather old itself,
dating back to when this was a real issue.  I agree that new compilers
shouldn't need to check.  New compilers shouldn't have to support ancient
code just as new code shouldn't have to worry about ancient compilers.

> -- 
> Richard Todd	Fido:1:147/1     USSnail:820 Annie Court,Norman OK 73069
> Try one of these: rmtodd at chinet.uucp, rmtodd at killer.dallas.tx.us,
>    rmtodd at uokmax.ecn.uoknor.edu  or ...!sun!texsun!uokmax!rmtodd.
> "MSDOS is a Neanderthal operating system" - Henry Spencer


Dave Rorke
att!attunix!der



More information about the Comp.unix.wizards mailing list