lsym_period.c revision 1.3
1/* $NetBSD: lsym_period.c,v 1.3 2022/04/23 09:59:14 rillig Exp $ */
2
3/*
4 * Tests for the token lsym_period, which represents '.' in these contexts:
5 *
6 * In an initializer, '.' starts a named designator (since C99).
7 *
8 * In an expression, 'sou.member' accesses the member 'member' in the struct
9 * or union 'sou'.
10 *
11 * In a function prototype declaration, the sequence '.' '.' '.' marks the
12 * start of a variable number of arguments.  It would have been more intuitive
13 * to model them as a single token, but it doesn't make any difference for
14 * formatting the code.
15 *
16 * See also:
17 *	lsym_word.c		for '.' inside numeric constants
18 */
19
20/* Designators in an initialization */
21#indent input
22struct point {
23	int x;
24	int y;
25} p = {
26	.x = 3,
27	.y = 4,
28};
29#indent end
30
31#indent run-equals-input -di0
32
33
34/* Accessing struct members */
35#indent input
36time_t
37get_time(struct stat st)
38{
39	return st.st_mtime > 0 ? st . st_atime : st.st_ctime;
40}
41#indent end
42
43#indent run
44time_t
45/* $ FIXME: The '{' must be in the next line. */
46get_time(struct stat st){
47	return st.st_mtime > 0 ? st.st_atime : st.st_ctime;
48}
49#indent end
50
51#indent run -Ttime_t
52time_t
53get_time(struct stat st)
54{
55	return st.st_mtime > 0 ? st.st_atime : st.st_ctime;
56}
57#indent end
58
59
60/* Varargs in a function declaration */
61#indent input
62void my_printf(const char *, ...);
63#indent end
64
65#indent run-equals-input -di0
66