lex_integer.c revision 1.7
1/*	$NetBSD: lex_integer.c,v 1.7 2021/08/21 11:50:57 rillig Exp $	*/
2# 3 "lex_integer.c"
3
4/*
5 * Tests for lexical analysis of integer constants.
6 *
7 * C99 6.4.4.1 "Integer constants"
8 */
9
10/* lint1-only-if: lp64 */
11
12void sinki(int);
13void sinku(unsigned int);
14
15/* All platforms supported by lint have 32-bit int in two's complement. */
16void
17test_signed_int(void)
18{
19	sinki(0);
20
21	sinki(-1);
22
23	sinki(2147483647);
24
25	/* expect+2: converted from 'long' to 'int' due to prototype */
26	/* expect+1: conversion of 'long' to 'int' is out of range */
27	sinki(2147483648);
28
29	sinki(-2147483647);
30
31	/* expect+1: converted from 'long' to 'int' due to prototype */
32	sinki(-2147483648);
33}
34
35void
36test_unsigned_int(void)
37{
38	sinku(0);
39
40	sinku(4294967295U);
41
42	/* expect+2: from 'unsigned long' to 'unsigned int' due to prototype */
43	/* expect+1: conversion of 'unsigned long' to 'unsigned int' is out of range */
44	sinku(4294967296U);
45}
46
47void sinkull(unsigned long long);
48
49void
50suffixes(void)
51{
52	sinkull(3u);
53	sinkull(3ll);
54	sinkull(3llu);
55	sinkull(3Ull);
56
57	/* The 'LL' must not be split. Checked by the compiler. */
58	sinkull(3lul);
59	/* The 'Ll' must not used mixed case. Checked by the compiler. */
60	sinkull(3ULl);
61}
62
63/* https://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html */
64void
65binary_literal(void)
66{
67	sinku(0b1111000001011010);
68}
69