Instead of using short and long data type, the example code uses Word16 for the 16-
bit integer data type and Word32 for the 32-bit data type. In addition, the three integer
types (int, short, and long) can be declared as unsigned by preceding the declaration
with unsigned. For example,
unsigned int counter;
where counter has a value range from 0 to 65 535.
Statements and expressions using the operators should normally use variables and
constants of the same type. If data types are mixed, C uses two basic rules to auto-
matically make type conversions:
1. If an operation involves two types, the value with a lower rank is converted to the
type of higher rank. This process is called promotion, and the ranking from highest
to lowest type is double, float, long, int, short, and char.
2. In an assignment statement, the result is converted to the type of the variable that is
being assigned. This may result in promotion or demotion when the value is
truncated to a lower ranking type.
Sometimes the conversion must be stated explicitly in order to demand that a con-
version be done in a certain way. A cast operator places the name of the desired type in
parentheses before the variable or expression, thus allowing us to specify a type change
in the value. For example, the data casting(int)used in the following expressions
treats the floating-point number z as an integer:
int x, y;
float z 2.8;
x (int)z;
/* Truncate z to an integer x */
y (int)(z0.5); /* Rounding z to an integer y */
The casting result will truncate 2.8 to 2 and store it in x, and allows rounding of the
floating variable z to an integer 3 and stores it in y.
C.1.3 Arrays
An array groups distinct variables of the same type under a single name. A one-dimen-
sional array can be visualized as a list of values arranged in either a row or a column. We
assign an identifier to an array, and then distinguish between elements or values in the
array by using subscripts. The subscripts always start with 0 and are incremented by 1. In
C, all data types can be declared as an array by placing the number of elements to be
assigned to an array in brackets after its name. One-dimensional array is declared as
data_type array_name [N];
where the array_name is the name of an array of N elements of data type specified. For
example,
float y [5];
474
APPENDIX C: INTRODUCTION OF C PROGRAMMING FOR DSP APPLICATIONS