2. Embedded QUEL for C : C Variables and Data Types : Variable Usage : Using an Enumerated Variable (Enum)
 
Share this page                  
Using an Enumerated Variable (Enum)
The syntax for referring to an enumerated variable or enumerated literal is the same as referring to a simple variable:
enum_name
Enumerated variables are treated as integer variables when referenced and can be used to retrieve data from and assign data to Ingres. The enumerated literals are treated as integer constants and follow the same rules as integer constants declared with the ##define statement. Enumerated variables can only be used to assign data to Ingres.
The following program fragment demonstrates a simple example of the enumerated type "color":
##  typedef enum {red, white, blue} color;

##  color col_var, *col_ptr;

##  static color col_arr[3] = {blue, white, red};

##  int i;

     /* Mapping from color to string */
     static char *col_to_str_arr[3] = 
       {"red","white","blue"};
#    define ctos(c) col_to_str_arr[(int)c];
     /* Fill rows with color array */
     for (i = 0; i < 3; i++)
##     append clr (num = i+1, color = col_arr[i])

     /*
     ** Retrieve the rows -demonstrating a color variable
     ** and pointer, and arithmetic on a stored color
     ** value. Results are:
     **     [1] blue, red
     **     [2] white, blue
     **     [3] red, white
     */
            col_ptr = &col_arr[0];
##          retrieve (i = clr.num, col_var = clr.color,
##          *col_ptr = clr.color+1)
##          {
               printf("[%d] %s, %s\n", i, ctos(col_var),
               ctos(*col_ptr%3));
##          }