Page 25 - Programming Microcontrollers in C
P. 25

10     Chapter 1  Introduction to C

                              long—modifies an int, and is a variable size whose width is
                          no less than that of an int. For example, on a 16-bit machine, an
                          int might be 16 bits, and a long int could be 32 bits. long can
                          also modify a double to specify an extended precision floating-point
                          number. You will find examples where a long and an int are the
                          same size.
                              signed—modifies all integral numbers and produces a range
                          of numbers that contains both positive and negative numbers. For
                          example, if the type char is 8 bits, a signed char can contain the
                          range of numbers –128 to +127. Default for char and int is
                          signed when they are declared.

                              unsigned—modifies all integral numbers and produces a range
                          of numbers that are positive only. For example, if the type char is 8
                          bits, an unsigned char can contain the range of numbers 0 to
                          +255. It is not necessary to include the type int with the qualifiers
                          short or long. Thus, the following statements are the same:
                   long int a,c;
                   short int d;
                           and

                   long a,c;
                   short d;
                              When a variable is defined, space is allocated in memory for its
                          storage. The basic variable size is implementation dependent, and
                          especially for microcontrollers, you will find that this variability will
                          show up when you change from one microcomputer to another.
                              Each variable must be defined prior to being used. A variable
                          may be defined at the beginning of any code block, and the variable’s
                          scope is the block in which it is defined. When the block in which the
                          variable is defined is exited, the variable goes out of existence. There
                          is no problem with defining variables with the same name in differ­
                          ent blocks. The compiler will make certain that these variables do
                          not get mixed up in the execution of the code.
                              An additional qualifier is const. When const is used as a quali­
                          fier on the declaration of any variable, an initialization value must be
                          declared. This value cannot be changed by the program. Therefore
                          the declaration
   20   21   22   23   24   25   26   27   28   29   30