← Back to davo.co
aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
blob: 73c21a4a76caf87aef8bf39e31c5434ae5bef9e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "c23-fallback.h"
#include <stdio.h>

typedef enum echar echar;
enum echar {
  mchar = UCHAR_MAX,
};

typedef enum eshort eshort;
enum eshort {
  mshort = USHRT_MAX,
};

typedef enum eint eint;
enum eint {
  mint = UINT_MAX,
};

typedef enum elong elong;
enum elong {
  mlong = ULONG_MAX,
};

typedef enum ellong ellong;
enum ellong {
  mllong = ULLONG_MAX,
};

#ifdef UINT128_MAX
typedef enum e128 e128;
enum e128 {
  m128 = UINT128_MAX,
};
#endif

#if __has_feature(c_fixed_enum) || (__clang_major__ > 7)

enum fchar : unsigned char {
  nchar = UCHAR_MAX,
};
typedef enum fchar fchar;

enum fshort : unsigned short {
  nshort = USHRT_MAX,
};
typedef enum fshort fshort;

enum fint : unsigned {
  nint = UINT_MAX,
};
typedef enum fint fint;

enum flong : unsigned long {
  nlong = ULONG_MAX,
};
typedef enum flong flong;

enum fllong : unsigned long long {
  nllong = ULLONG_MAX,
};
typedef enum fllong fllong;

#ifdef UINT128_MAX
enum f128 : uint128_t {
  n128 = UINT128_MAX,
};
typedef enum f128 f128;
#endif
#else
# warning "test for fixed underlying integer type skipped"
#endif

int main(void) {
  printf("echar:\t%zu\t%zu\n", sizeof(echar), sizeof(mchar));
  printf("eshort:\t%zu\t%zu\n", sizeof(eshort), sizeof(mshort));
  printf("eint:\t%zu\t%zu\n", sizeof(eint), sizeof(mint));
  printf("elong:\t%zu\t%zu\n", sizeof(elong), sizeof(mlong));
  printf("ellong:\t%zu\t%zu\n", sizeof(ellong), sizeof(mllong));
#ifdef UINT128_MAX
  printf("e128:\t%zu\t%zu\n", sizeof(e128), sizeof(m128));
#endif

#if __has_feature(c_fixed_enum) || (__clang_major__ > 7)
  printf("fchar:\t%zu\t%zu\n", sizeof(fchar), sizeof(nchar));
  printf("fshort:\t%zu\t%zu\n", sizeof(fshort), sizeof(nshort));
  printf("fint:\t%zu\t%zu\n", sizeof(fint), sizeof(nint));
  printf("flong:\t%zu\t%zu\n", sizeof(flong), sizeof(nlong));
  printf("fllong:\t%zu\t%zu\n", sizeof(fllong), sizeof(nllong));
# ifdef UINT128_MAX
  printf("f128:\t%zu\t%zu\n", sizeof(f128), sizeof(n128));
# endif
#endif
}