Previous Table of Contents "New C Standard" commentary
typedef-name: identifier
1630 If a typedef name specifies a variably modified type then it shall have block scope.
1631
In a declaration whose storage-class specifier is
1632 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.
1633
A
1634 That is, in the following declarations:
typedef T type_ident;
type_ident D;
1635 A typedef name shares the same name space as other identifiers declared in ordinary declarators.
1636 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
1637 EXAMPLE 2 After the declarations
typedef struct s1 { int x; } t1, *tp1;
typedef struct s2 { int x; } t2, *tp2;
type
1638 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
1639 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);
1640 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: 2008-01-30 02:39:44
The text from WG14/N1256 is copyright © ISO