Variable Declarations Syntax
The syntax of a variable declaration is:
[storage_class] [class_modifier] type_specification
declarator {, declarator};
where each declarator is:
variable_name [= initial_value]
Note:
• Storage_class is optional but, if specified, can be any of the following:
auto
extern
register
static
varchar
VMS: The following storage classes are VMS only:
globaldef
globalref
The storage class provides no data type information to the preprocessor. The varchar storage class is described in more detail later.
• Class_modifier is optional, and can be one of the following:
const
volatile
The class modifier provides no information to the preprocessor, and is merely passed through to the C compiler. Use of const and volatile keywords in ESQL/C data declarations is supported to the extent specified in the ANSI/ISO SQL-92 standard for embedded SQL C. That does not include all the possible uses of const and volatile that are accepted by the C compiler.
• Begin a variable or type name with an alphabetic character, but follow it with alphanumeric characters or underscores.
• Although register variables are supported, be careful when using them in embedded SQL statements. In input/output statements, such as the insert and select statements, you can pass a variable by reference with the ampersand operator (&). Some compilers do not allow you to use register variables this way.
• The type_specification must be an embedded SQL/C type, a type built up with a typedef declaration (and known to the preprocessor), or a structure or union specification. Typedef declarations and structures are discussed in detail later.
• Precede the variable_name by an asterisk (*), to denote a pointer variable, or follow it with a bracketed expression ([expr]), to denote an array variable. Pointers and arrays are discussed in more detail later.
• Begin the variable_name, which must be a legal C identifier name, with an underscore or alphabetic character.
• Variable names are case sensitive; that is, a variable named empid is different from one named Empid.
• Do not use a previously defined typedef name for a variable name. This also applies to any variable name that is the name of a field in a structure declaration.
• The preprocessor does not parse initial_value. Consequently, the preprocessor accepts any initial value, even if it can later cause a C compiler error. For example, the preprocessor accepts both of the following initializations, even though only the first is a legal C statement:
char *msg = "Try again";
int rowcount = {0, 123};
Example: Variable declarations usage
extern int first_employee;
auto long update_mode = 1;
static char *names[3] = {"neil","mark","barbara"};
static char *names[3] = {"john","bob","tom"};
char **nameptr = names;
short name_counter;
float last_salary = 0.0, cur_salary = 0.0;
double stat_matrix[STAT_ROWS][STAT_COLS];
const char xyz[] = "xyz";