Expert C Programming

(Jeff_L) #1

The original IBM PC monitor operated at a horizontal scan rate provided by the video
controller chip. The flyback transformer (the gadget that produces the high voltage needed
to accelerate the electrons to light up the phosphors on the monitor) relied on this being a
reasonable frequency. However, it was possible, in software, to set the video chip scan rate
to zero, thus feeding a constant voltage into the primary side of the transformer. It then
acted as a resistor, and dissipated its power as heat rather than transforming it up onto the
screen. This burned the monitor out in seconds. Voilà: undefined software behavior causes
system meltdown!


Portable Code:


strictly-conforming— A strictly-conforming program is one that:



  • only uses specified features.

  • doesn't exceed any implementation-defined limit.

  • has no output that depends on implementation-defined, unspecified, or undefined features.


This was intended to describe maximally portable programs, which will always produce the identical
output whatever they are run on. In fact, it is not a very interesting class because it is so small
compared to the universe of conforming programs. For example, the following program is not strictly
conforming:


#include <limits.h>


#include <stdio.h>


int main() { (void) printf("biggest int is %d", INT_MAX);


return 0;}


/ not strictly conforming: implementation-defined output! /


For the rest of this book, we usually don't try to make the example programs be strictly conforming. It
clutters up the text, and makes it harder to see the specific point under discussion. Program portability
is valuable, so you should always put the necessary casts, return values, and so on in your real-world
code.


conforming— A conforming program can depend on the nonportable features of an implementation.
So a program is conforming with respect to a specific implementation, and the same program may be
nonconforming using a different compiler. It can have extensions, but not extensions that alter the
behavior of a strictly-conforming program. This rule is not a constraint, however, so don't expect the
compiler to warn you about violations that render your program nonconforming!


The program example above is conforming.


Translation Limits


The ANSI C standard actually specifies lower limits on the sizes of programs that must successfully
translate. These are specified in paragraph 5.2.4.1. Most languages say how many characters can be in
a dataname, and some languages stipulate what limit is acceptable for the maximum number of array
dimensions. But specifying lower bounds on the sizes of various other features is unusual, not to say

Free download pdf