Expert C Programming

(Jeff_L) #1

static unsigned short stopwatch[] =


{


s X X X X X X X _ ,


s X X X X X X X X X X X X ,


s X X X X X X X X ,


s X X X X ,


s X X X X ,


s X X X X ,


s X X X X ,


s X X X X X X X X X _ ,


s X X X X X _ ,


s X X X X X _ ,


s X X X X X _ ,


s X X X X X _ ,


s X X X X X X ,


s X X X X X X X X X _ ,


s X X X X X _ ,


s


};


certainly quite a bit more meaningful than the equivalent literal values. Standard C has octal, decimal,
and hexadecimal constants, but not binary constants, which would otherwise be a simpler way of
picturing the pattern.


If you hold the book at the right angle and squint at the page, you might even have a chance of
guessing that this is the little stopwatch "cursor busy" glyph used on popular window systems. We got
this tip from the Usenet comp.lang.c newsgroup some years ago.


Don't forget to undefine the macros after your pictures; you don't want them mysteriously interfering
with later code.


Types Changed While You Wait


We saw in Chapter 1 the type conversions that occur when operators are supplied operands of different
types. These are known as the "usual arithmetic conversions", and they govern conversions between
two different types to a common type, which is usually also the result type.


Type conversions in C are much more widespread than is generally realized. They can also occur in
any expression that involves a type smaller than int or double. Take the following code, for
example:


printf(" %d ", sizeof 'A' );


The code prints out the size of the type that holds a character literal. Surely this will be the size of a
character, and hence "1"? Try running the code. You will see you actually get "4" (or whatever size
int is on your system). Character literals have type int and they get there by following the rules for
promotion from type char. This is too briefly covered in K&R 1, on page 39 where it says:

Free download pdf