typedef-name: identifier
1619 If a typedef name specifies a variably modified type then it shall have block scope.
1620
In a declaration whose storage-class specifier is
1621 Any array size expressions associated with variable length array declarators are evaluated each time the declaration of the typedef name is reached in the order of execution.
1622
A
1623 That is, in the following declarations:
typedef T type_ident;
type_ident D;
1624 A typedef name shares the same name space as other identifiers declared in ordinary declarators.
1625 EXAMPLE 1 After
typedef int MILES, KLICKSP();
typedef struct { double hi, lo; } range;
the constructions
MILES distance;
extern KLICKSP *metricp;
range x;
range z, *zp;
are all valid declarations. The type of
1626 EXAMPLE 2 After the declarations
typedef struct s1 { int x; } t1, *tp1;
typedef struct s2 { int x; } t2, *tp2;
type
1627 EXAMPLE 3 The following obscure constructions
typedef signed int t;
typedef int plain;
struct tag {
unsigned t:4;
const t:5;
plain r:5;
};
declare a typedef name
t f(t (t));
long t;
then a function
1628 EXAMPLE 4
On the other hand, typedef names can be used to improve code
readability. All three of the following declarations of the
typedef void fv(int), (*pfv)(int);
void (*signal(int, void (*)(int)))(int);
fv *signal(int, fv *);
pfv signal(int, pfv);
1629 EXAMPLE 5 If a typedef name denotes a variable length array type, the length of the array is fixed at the time the typedef name is defined, not each time it is used:
void copyt(int n)
{
typedef int B[n]; // B is n ints, n evaluated now
n += 1;
B a; // a is n ints, n without += 1
int b[n]; // a and b are different sizes
for (int i = 1; i < n; i++)
a[i-1] = b[i];
}
Next
Created at: 2005-06-29 02:19:02
The text from WG14/N1124 is copyright © ISO