Page 251 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 251

228                                    Chapter 8 Programming in C and C++











                                                                              >*























                                Figure 83. Loop Statements

        contents of the word pointed to by a, which is the contents of b. (Note that a*b is a
        times b but *b is the contents of the word pointed to by b.) Whenever you see &,
        read it as "address of," and whenever you see *, read it as "contents of thing pointed to
        by." In a declaration statement, the statement char *p; means that the thing pointed to
        by p is a character, and p points to (contains the address of) a character. In an
        assignment statement, *p = 1; means that 1 is assigned to the value of the thing
        pointed to by p, whereas p*l; means that the pointer p is given the value 1.
        Similarly, a=*p; means that a is given the value of the thing pointed to by p, while
        a^p; means a gets the value of the pointer p. C compilers can give an error message
        when you assign an integer to a pointer. If that occurs, you have to use a cast. Write p
        ~ (int *) 0x4000; to tell the compiler 0x4000 is really a pointer value to an integer
        and not an integer itself.
            Constants can be defined by define or enum statements, put before any declarations
        or statements, to equate names to values. The define statement begins with the
        characters #def ine and does not end with a semicolon.
             #define ALPHA 100
        Thenceforth, we can use the label ALPHA throughout the program, and 100 will
        effectively be put in place of ALPHA just before the program is actually compiled. This
        permits the program to be better documented, using meaningful labels, and easier to
        maintain, so that if the value of a label is changed, it is changed everywhere it occurs.
   246   247   248   249   250   251   252   253   254   255   256