3.3 Type Specifiers

Type specifiers in declarations define the type of a variable or function declaration.

Syntax

type-specifier :
void
char
short
int
long
float
double
signed
unsigned

struct-or-union-specifier
enum-specifier
typedef-name

The signed char, signed int, signed short int, and signed long int types, together with their unsigned counterparts and enum, are called “integral” types. The float, double, and long double type specifiers are referred to as “floating” or “floating-point” types. You can use any integral or floating-point type specifier in a variable or function declaration. If a type-specifier is not provided in a declaration, it is taken to be int.

The optional keywords signed and unsigned can precede or follow any of the integral types, except enum, and can also be used alone as type specifiers, in which case they are understood as signed int and unsigned int, respectively. When used alone, the keyword int is assumed to be signed. When used alone, the keywords long and short are understood as long int and short int.

Enumeration types are considered basic types. Type specifiers for enumeration types are discussed in “Enumeration Declarations”.

The keyword void has three uses: to specify a function return type, to specify an argument-type list for a function that takes no arguments, and to specify a pointer to an unspecified type. You can use the void type to declare functions that return no value or to declare a pointer to an unspecified type. See “Arguments” for information on void when it appears alone within the parentheses following a function name.

Type void expressions are evaluated for side effects. You cannot use the (nonexistent) value of an expression that has type void in any way, nor can you convert a void expression (by implicit or explicit conversion) to any type except void. If you do use an expression of any other type in a context where a void expression is required, its value is discarded.

You can create additional type specifiers with typedef declarations, as described in “Typedef Declarations”. See topic for information on the size of each type.

This manual generally uses the forms of the type specifiers listed in Table 3.1 rather than the long forms, and it assumes that the char type is signed by default. Therefore, throughout this manual, char is equivalent to signed char.

Table 3.1 Type Specifiers and Equivalents

Type Specifier Equivalent(s)

signed char1 char
signed int signed, int
signed short int short, signed short
signed long int long, signed long
unsigned char1
unsigned int unsigned
unsigned short int unsigned short
unsigned long int unsigned long
float
long double

1 When you make the char type unsigned by default (by specifying the /J compiler option), you cannot abbreviate signed char or unsigned char as char.

Microsoft Specific

You can specify the /J compiler option to change the default chartype from signed to unsigned. When this option is in effect, charmeans the same as unsigned char, and you must use the signedkeyword to declare a signed character value. The /J command-line option does not effect a charvalue that is explicitly declared signed. The chartype is zero-extended, not sign-extended, when /J is specified. ¨