Skip to content

Commit c110441

Browse files
authored
Merge pull request systemd#9058 from keszybz/fun-with-uint64_c
Fun with UINT64_C
2 parents 930362a + b49c6ca commit c110441

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/nspawn/nspawn-settings.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,19 @@ typedef enum SettingsMask {
5656
SETTING_CPU_AFFINITY = UINT64_C(1) << 20,
5757
SETTING_RLIMIT_FIRST = UINT64_C(1) << 21, /* we define one bit per resource limit here */
5858
SETTING_RLIMIT_LAST = UINT64_C(1) << (21 + _RLIMIT_MAX - 1),
59-
_SETTINGS_MASK_ALL = (UINT64_C(1) << (21 + _RLIMIT_MAX)) - 1
59+
_SETTINGS_MASK_ALL = (UINT64_C(1) << (21 + _RLIMIT_MAX)) - 1,
60+
_FORCE_ENUM_WIDTH = UINT64_MAX
6061
} SettingsMask;
6162

63+
/* We want to use SETTING_RLIMIT_FIRST in shifts, so make sure it is really 64 bits
64+
* when used in expressions. */
65+
#define SETTING_RLIMIT_FIRST ((uint64_t) SETTING_RLIMIT_FIRST)
66+
#define SETTING_RLIMIT_LAST ((uint64_t) SETTING_RLIMIT_LAST)
67+
68+
assert_cc(sizeof(SettingsMask) == 8);
69+
assert_cc(sizeof(SETTING_RLIMIT_FIRST) == 8);
70+
assert_cc(sizeof(SETTING_RLIMIT_LAST) == 8);
71+
6272
typedef struct Settings {
6373
/* [Run] */
6474
StartMode start_mode;

src/systemd/sd-resolve.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, co
4343
typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
4444

4545
enum {
46-
SD_RESOLVE_GET_HOST = UINT64_C(1),
47-
SD_RESOLVE_GET_SERVICE = UINT64_C(2),
48-
SD_RESOLVE_GET_BOTH = UINT64_C(3),
46+
SD_RESOLVE_GET_HOST = 1 << 0,
47+
SD_RESOLVE_GET_SERVICE = 1 << 1,
48+
SD_RESOLVE_GET_BOTH = SD_RESOLVE_GET_HOST | SD_RESOLVE_GET_SERVICE,
4949
};
5050

5151
int sd_resolve_default(sd_resolve **ret);

src/test/test-sizeof.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ enum Enum {
2626
};
2727

2828
enum BigEnum {
29-
big_enum_value = UINT64_C(-1),
29+
big_enum_value = UINT64_C(1),
30+
};
31+
32+
enum BigEnum2 {
33+
big_enum2_pos = UINT64_C(1),
34+
big_enum2_neg = UINT64_C(-1),
3035
};
3136

3237
int main(void) {
@@ -55,6 +60,10 @@ int main(void) {
5560

5661
info(enum Enum);
5762
info(enum BigEnum);
63+
info(enum BigEnum2);
64+
assert_cc(sizeof(enum BigEnum2) == 8);
65+
printf("big_enum2_pos → %zu\n", sizeof(big_enum2_pos));
66+
printf("big_enum2_neg → %zu\n", sizeof(big_enum2_neg));
5867

5968
return 0;
6069
}

0 commit comments

Comments
 (0)