What should be added to C

Wayne A. Christopher faustus at cad.BERKELEY.EDU
Thu May 29 08:23:39 AEST 1986


In article <1497 at mmintl.UUCP>, franka at mmintl.UUCP writes:

 > You would write:
 > 
 >   if (A) {
 >     X
 >   } andif (B) {
 >     Y
 >   } else {
 >     Z
 >   }
 > 
 > This is equivalent to:
 > 
 >    if (!(A)) goto _Z;
 >    X
 >    if (B) {
 >      Y
 >    } else {
 > _Z:
 >      Z
 >    }

It is also equivalent to:

	if (A) {
		X
		if (B) {
			Y
		}
	}
	if (!A || !B)
		Z
	}

I think this looks cleaner, but in any case it isn't an often-encountered
situation and the semantics aren't obvious.

 > To write more sophisticated macros.  For example, one could write a copy
 > macro which would invoke strcpy in most cases, but a word copy routine to
 > copy an array of structures whose size is a multiple of a word.  Such a
 > macro would be machine dependant -- this is exactly the reason for making it
 > a macro, instead of hard coding the calls.

You can write arbitrarily large macros by putting backslashes at the end of
lines.  This is ugly but it works.

 > Confusing "=" and "==" in if statements is a common mistake.  If "=" is not
 > a legal operator, this error becomes very rare.

It's also an extra character to type.  If you are prone to this sort of
error, just run your code through grep if | grep = | grep -v == ...

 > >The trouble with adding new features to C is that there is a very
 > >strong incentive not to use them.  After all, any program that
 > >uses some new feature is only going to run on machines that support
 > >that feature.  I don't think I'm going to be using only one compiler
 > >for the rest of my life and would like to avoid changing my code
 > >every time the environment hiccups.
 > 
 > This is the whole point of having a standard.  It gives you some assurance
 > that compilers which use the features will be available.

If the standard has all the things you enumerate, not many people will follow
it and it will be worse than no standard at all.

	Wayne



More information about the Comp.lang.c mailing list