1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include <stdio.h>
enum fred
{
a,
b,
c,
d,
e = 54,
f = 73,
g,
h
};
/* All following uses of enum efoo should compile
without warning. While forward enums aren't ISO C,
it's accepted by GCC also in strict mode, and only warned
about with -pedantic. This happens in the real world. */
/* Strict ISO C doesn't allow this kind of forward declaration of
enums, but GCC accepts it (and gives only pedantic warning), and
it occurs in the wild. */
enum efoo;
struct Sforward_use {
int (*fmember) (enum efoo x);
};
extern enum efoo it_real_fn(void);
enum efoo {
ONE,
TWO,
};
struct S2 {
enum efoo (*f2) (void);
};
void should_compile(struct S2 *s)
{
s->f2 = it_real_fn;
}
enum efoo it_real_fn(void)
{
return TWO;
}
static unsigned int deref_uintptr(unsigned int *p)
{
return *p;
}
enum Epositive {
epos_one, epos_two
};
int main()
{
enum fred frod;
enum Epositive epos = epos_two;
printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h);
/* printf("%d\n", frod); */
frod = 12;
printf("%d\n", frod);
frod = e;
printf("%d\n", frod);
/* Following should compile without warning. */
printf ("enum to int: %u\n", deref_uintptr(&epos));
return 0;
}
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|