chiark / gitweb /
tree-wide: drop license boilerplate
[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
8 #include <stdio.h>
9 #include <string.h>
10
11 #include "time-util.h"
12
13 /* Print information about various types. Useful when diagnosing
14  * gcc diagnostics on an unfamiliar architecture. */
15
16 #pragma GCC diagnostic ignored "-Wtype-limits"
17
18 #define info(t)                                                 \
19         printf("%s → %zu bits%s\n", STRINGIFY(t),               \
20                sizeof(t)*CHAR_BIT,                              \
21                strstr(STRINGIFY(t), "signed") ? "" :            \
22                ((t)-1 < (t)0 ? ", signed" : ", unsigned"));
23
24 enum Enum {
25         enum_value,
26 };
27
28 enum BigEnum {
29         big_enum_value = UINT64_C(-1),
30 };
31
32 int main(void) {
33         info(char);
34         info(signed char);
35         info(unsigned char);
36         info(short unsigned);
37         info(unsigned);
38         info(long unsigned);
39         info(long long unsigned);
40 #ifdef __GLIBC__
41         info(__syscall_ulong_t);
42         info(__syscall_slong_t);
43 #endif // ifdef __GLIBC__
44
45         info(float);
46         info(double);
47         info(long double);
48
49         info(size_t);
50         info(ssize_t);
51         info(time_t);
52         info(usec_t);
53 #ifdef __GLIBC__
54         info(__time_t);
55 #endif // ifdef __GLIBC__
56         info(pid_t);
57         info(uid_t);
58         info(gid_t);
59
60         info(enum Enum);
61         info(enum BigEnum);
62
63         return 0;
64 }