]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-sizeof.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / test / test-sizeof.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
fed527aa 2
61d1a5a2 3#include <stdio.h>
dccca82b 4#include <string.h>
61d1a5a2 5
54781add
ZJS
6#define __STDC_WANT_IEC_60559_TYPES_EXT__
7#include <float.h>
8
fed527aa
ZJS
9#include "time-util.h"
10
11/* Print information about various types. Useful when diagnosing
12 * gcc diagnostics on an unfamiliar architecture. */
13
14#pragma GCC diagnostic ignored "-Wtype-limits"
15
23cfbcc3
ZJS
16#define info(t) \
17 printf("%s → %zu bits%s, %zu byte alignment\n", STRINGIFY(t), \
18 sizeof(t)*CHAR_BIT, \
19 strstr(STRINGIFY(t), "signed") ? "" : \
20 (t)-1 < (t)0 ? ", signed" : ", unsigned", \
21 __alignof__(t))
fed527aa 22
26e1f724
ZJS
23enum Enum {
24 enum_value,
25};
26
27enum BigEnum {
994282d2
ZJS
28 big_enum_value = UINT64_C(1),
29};
30
31enum BigEnum2 {
32 big_enum2_pos = UINT64_C(1),
33 big_enum2_neg = UINT64_C(-1),
26e1f724
ZJS
34};
35
fed527aa
ZJS
36int main(void) {
37 info(char);
38 info(signed char);
39 info(unsigned char);
40 info(short unsigned);
41 info(unsigned);
42 info(long unsigned);
43 info(long long unsigned);
0c183e96
ZJS
44 info(__syscall_ulong_t);
45 info(__syscall_slong_t);
fed527aa
ZJS
46
47 info(float);
48 info(double);
49 info(long double);
50
54781add 51#ifdef FLT128_MAX
e07d3893
ZJS
52 info(_Float128);
53 info(_Float64);
54 info(_Float64x);
55 info(_Float32);
56 info(_Float32x);
57#endif
58
fed527aa
ZJS
59 info(size_t);
60 info(ssize_t);
61 info(time_t);
62 info(usec_t);
0c183e96 63 info(__time_t);
98d93199 64 info(pid_t);
85f8fa4d 65 info(uid_t);
98d93199 66 info(gid_t);
fed527aa 67
26e1f724
ZJS
68 info(enum Enum);
69 info(enum BigEnum);
994282d2
ZJS
70 info(enum BigEnum2);
71 assert_cc(sizeof(enum BigEnum2) == 8);
72 printf("big_enum2_pos → %zu\n", sizeof(big_enum2_pos));
73 printf("big_enum2_neg → %zu\n", sizeof(big_enum2_neg));
26e1f724 74
fed527aa
ZJS
75 return 0;
76}