blob: 3b73e11c177a27be5f1b9b21ba0adc785524db57 (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* $NetBSD: lsym_colon.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
/*
* Tests for the token lsym_colon, which represents a ':' in these contexts:
*
* After a label that is the target of a 'goto' statement.
*
* In a 'switch' statement, after a 'case' label or a 'default' label.
*
* As part of the conditional operator '?:'.
*
* In the declaration of a struct member that is a bit-field.
*
* Since C11, in the _Generic selection to separate the type from its
* corresponding expression.
*
* See also:
* label.c
* lsym_case_label.c for the C11 _Generic expression
* lsym_question.c
*/
/*
* The ':' marks a label that can be used in a 'goto' statement.
*/
//indent input
void endless(void)
{
label1:
goto label2;
if (true)if (true)if (true)if (true)label2 :goto label1;
}
//indent end
//indent run
void
endless(void)
{
label1:
goto label2;
if (true)
if (true)
if (true)
if (true)
label2: goto label1;
}
//indent end
/*
* The ':' is used in a 'switch' statement, after a 'case' label or a
* 'default' label.
*/
//indent input
void
example(void)
{
switch (expr) {
case 'x':
return;
default:
return;
}
}
//indent end
//indent run-equals-input
/*
* The ':' is used as part of the conditional operator '?:'.
*/
//indent input
int constant_expression = true?4:12345;
//indent end
//indent run
int constant_expression = true ? 4 : 12345;
//indent end
/*
* The ':' is used in the declaration of a struct member that is a bit-field.
*/
//indent input
struct bit_field {
bool flag:1;
int maybe_signed : 4;
signed int definitely_signed:3;
signed int : 0;/* padding */
unsigned int definitely_unsigned:3;
unsigned int:0;/* padding */
};
//indent end
//indent run
struct bit_field {
bool flag:1;
int maybe_signed:4;
signed int definitely_signed:3;
/* $ XXX: Placing the colon directly at the type looks inconsistent. */
signed int: 0; /* padding */
unsigned int definitely_unsigned:3;
/* $ XXX: Placing the colon directly at the type looks inconsistent. */
unsigned int: 0; /* padding */
};
//indent end
|