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