User`s manual

34 digi.com Language
4.12 Type Definitions
Both types and variables may be defined. One virtue of high-level languages such as C and Pascal is that
abstract data types can be defined. Once defined, the data types can be used as easily as simple data types
like int, char, and float. Consider this example.
Use typedef to create a meaningful name for a class of data. Consider this example.
This example shows many of the basic C constructs.
typedef int MILES; // a basic type named MILES
typedef struct { // a structure type...
float re; // ...
float im; // ...
} COMPLEX; // ...named COMPLEX
MILES distance; // declare variable of type MILES
COMPLEX z, *zp; // declare variable of & pointer to type COMPLEX .
typedef unsigned int node;
void NodeInit( node ); // type name is informative
void NodeInit( unsigned int ); // not very informative
/*Put descriptive information in your program code using this form of comment,
which can be inserted anywhere and can span lines. The double slash comment
(shown below) may be placed at the end of a line.*/
#define SIZE 12 // A symbolic constant defined.
int g, h; // Declare global integers.
float sumSquare( int, int ); // Prototypes for
void init(); // functions below.
main(){ // Program starts here.
float x; // x is local to main.
init(); // Call a void function.
x = sumSquare( g, h ); // x gets sumSquare value.
printf(“x = %f”,x); // printf is a standard function.
}
void init(){ // Void functions do things but
g = 10; // they return no value.
h = SIZE; // Here, it uses the symbolic
}// constant defined above.
float sumSquare( int a, int b ){ // Integer arguments.
float temp; // Local variables.
temp = a*a + b*b; // Arithmetic statement.
return( temp ); // Return value.
}
/* and here is the end of the program */