Expert C Programming

(Jeff_L) #1

One way of analyzing the deficiencies in a programming language is to consider the flaws in three
possible categories: things the language does that it shouldn't do; things it doesn't do that it should;
and things that are completely off the wall. For convenience, we can call these "sins of commission,"
"sins of omission," and "sins of mission," respectively. The following sections describe C features in
these categories.


This chapter isn't meant as fatal criticism of C. C is a wonderful programming language with many
strengths. Its popularity as the implementation language of choice on many platforms is well-deserved.
But, as my grandmother used to say, you can't run a super-conducting supercollider without smashing
a few atoms, and you can't analyze C without looking at the flaws as well as the high points.
Reviewing areas for improvement is one of the factors that gradually improves the science of software
engineering and the art of programming language design. That's why C++ is so disappointing: it does
nothing to address some of the most fundamental problems in C, and its most important addition
(classes) builds on the deficient C type model. So with the spirit of enquiry dedicated to improving
future languages, here are some observations and case histories.


Handy Heuristic


The One 'l' nul and the Two 'l' null


Memorize this little rhyme to recall the correct terminology for pointers and ASCII zero:


The one "l" NUL ends an ASCII string,


The two "l" NULL points to no thing.


Apologies to Ogden Nash, but the three "l" nulll means check your spelling. The ASCII
character with the bit pattern of zero is termed a "NUL". The special pointer value that
means the pointer points nowhere is "NULL". The two terms are not interchangeable in
meaning.


Sins of Commission


The "sins of commission" category covers things that the language does, that it shouldn't do. This
includes error-prone features like the switch statement, automatic concatenation of adjacent string
literals, and default global scope.


Switches Let You Down with Fall Through


The general form of a switch statement is:

Free download pdf