expr_promote_trad.c revision 1.6
1/*	$NetBSD: expr_promote_trad.c,v 1.6 2025/04/12 15:57:26 rillig Exp $	*/
2# 3 "expr_promote_trad.c"
3
4/*
5 * Test arithmetic promotions in traditional C.
6 */
7
8/* lint1-flags: -tw -X 351 */
9
10sink();
11
12struct arithmetic_types {
13	/* _Bool requires C90 or later */
14	char plain_char;
15	/* signed char requires C90 or later */
16	unsigned char unsigned_char;
17	short signed_short;
18	unsigned short unsigned_short;
19	int signed_int;
20	unsigned int unsigned_int;
21	long signed_long;
22	unsigned long unsigned_long;
23	/* (unsigned) long long requires C90 or later */
24	/* __int128_t requires C90 or later */
25	/* __uint128_t requires C90 or later */
26	float single_floating;
27	double double_floating;
28	/* long double requires C90 or later */
29	/* _Complex requires C90 or later */
30	enum {
31		E
32	} enumerator;
33};
34
35caller(arg)
36	struct arithmetic_types *arg;
37{
38	/* See expr_promote_trad.exp-ln for the resulting types. */
39	sink("",
40	    arg->plain_char,		/* gets promoted to 'int' */
41	    arg->unsigned_char,		/* gets promoted to 'unsigned int' */
42	    arg->signed_short,		/* gets promoted to 'int' */
43	    arg->unsigned_short,	/* gets promoted to 'unsigned int' */
44	    arg->signed_int,
45	    arg->unsigned_int,
46	    arg->signed_long,
47	    arg->unsigned_long,
48	    arg->single_floating,	/* gets promoted to 'double' */
49	    arg->double_floating,
50	    arg->enumerator);		/* should get promoted to 'int' */
51}
52
53/*
54 * XXX: Enumerations may need be promoted to 'int', at least C99 6.3.1.1p2
55 * suggests that: "If an int can represent ...".
56 */
57