chiark / gitweb /
Prep v238: Uncomment now needed headers and unmask now needed functions in src/test...
[elogind.git] / src / test / test-sizeof.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2016 Zbigniew Jędrzejewski-Szmek
6
7   systemd is free software; you can redistribute it and/or modify it
8   under the terms of the GNU Lesser General Public License as published by
9   the Free Software Foundation; either version 2.1 of the License, or
10   (at your option) any later version.
11
12   systemd is distributed in the hope that it will be useful, but
13   WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   Lesser General Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public License
18   along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "time-util.h"
25
26 /* Print information about various types. Useful when diagnosing
27  * gcc diagnostics on an unfamiliar architecture. */
28
29 #pragma GCC diagnostic ignored "-Wtype-limits"
30
31 #define info(t)                                                 \
32         printf("%s → %zu bits%s\n", STRINGIFY(t),               \
33                sizeof(t)*CHAR_BIT,                              \
34                strstr(STRINGIFY(t), "signed") ? "" :            \
35                ((t)-1 < (t)0 ? ", signed" : ", unsigned"));
36
37 enum Enum {
38         enum_value,
39 };
40
41 enum BigEnum {
42         big_enum_value = UINT64_C(-1),
43 };
44
45 int main(void) {
46         info(char);
47         info(signed char);
48         info(unsigned char);
49         info(short unsigned);
50         info(unsigned);
51         info(long unsigned);
52         info(long long unsigned);
53 #ifdef __GLIBC__
54         info(__syscall_ulong_t);
55         info(__syscall_slong_t);
56 #endif // ifdef __GLIBC__
57
58         info(float);
59         info(double);
60         info(long double);
61
62         info(size_t);
63         info(ssize_t);
64         info(time_t);
65         info(usec_t);
66 #ifdef __GLIBC__
67         info(__time_t);
68 #endif // ifdef __GLIBC__
69         info(pid_t);
70         info(uid_t);
71         info(gid_t);
72
73         info(enum Enum);
74         info(enum BigEnum);
75
76         return 0;
77 }