lsym_unary_op.c revision 1.5 1 /* $NetBSD: lsym_unary_op.c,v 1.5 2022/04/24 10:36:37 rillig Exp $ */
2
3 /*
4 * Tests for the token lsym_unary_op, which represents a unary operator.
5 *
6 * In an expression, a unary operator is written without blank next to its
7 * argument.
8 *
9 * In a type name, the "unary operator" '*' represents the derivation of a
10 * pointer type.
11 */
12
13 //indent input
14 void
15 unary_operators(void)
16 {
17 /* In the order of appearance in C11 6.5. */
18 function(a++, a--, ++a, --a, &a, *a, +a, -a, ~a, !a);
19 }
20 //indent end
21
22 //indent run-equals-input
23
24
25 /*
26 * The unary operators '+' and '-' can occur in long chains. In these chains,
27 * adjacent '+' must not be merged to '++' since that would be a different
28 * token. The same applies to '&', but that case is irrelevant in practice
29 * since the address of an address cannot be taken.
30 */
31 //indent input
32 int var=+3;
33 int mixed=+-+-+-+-+-+-+-+-+-+-+-+-+-3;
34 int count=~-~-~-~-~-~-~-~-~-~-~-~-~-3;
35 int same = + + + + + - - - - - 3;
36 //indent end
37
38 //indent run -di0
39 int var = +3;
40 int mixed = +-+-+-+-+-+-+-+-+-+-+-+-+-3;
41 int count = ~-~-~-~-~-~-~-~-~-~-~-~-~-3;
42 int same = + + + + +- - - - -3;
43 //indent end
44
45
46 /*
47 * A special kind of unary operator is '->', which additionally suppresses the
48 * next space.
49 */
50 //indent input
51 int var = p -> member;
52 //indent end
53
54 //indent run -di0
55 int var = p->member;
56 //indent end
57