1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-25 23:21:33 +03:00

Merge pull request #9058 from keszybz/fun-with-uint64_c

Fun with UINT64_C
This commit is contained in:
Lennart Poettering 2018-05-22 13:23:56 +02:00 committed by GitHub
commit c1104417b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -56,9 +56,19 @@ typedef enum SettingsMask {
SETTING_CPU_AFFINITY = UINT64_C(1) << 20,
SETTING_RLIMIT_FIRST = UINT64_C(1) << 21, /* we define one bit per resource limit here */
SETTING_RLIMIT_LAST = UINT64_C(1) << (21 + _RLIMIT_MAX - 1),
_SETTINGS_MASK_ALL = (UINT64_C(1) << (21 + _RLIMIT_MAX)) - 1
_SETTINGS_MASK_ALL = (UINT64_C(1) << (21 + _RLIMIT_MAX)) - 1,
_FORCE_ENUM_WIDTH = UINT64_MAX
} SettingsMask;
/* We want to use SETTING_RLIMIT_FIRST in shifts, so make sure it is really 64 bits
* when used in expressions. */
#define SETTING_RLIMIT_FIRST ((uint64_t) SETTING_RLIMIT_FIRST)
#define SETTING_RLIMIT_LAST ((uint64_t) SETTING_RLIMIT_LAST)
assert_cc(sizeof(SettingsMask) == 8);
assert_cc(sizeof(SETTING_RLIMIT_FIRST) == 8);
assert_cc(sizeof(SETTING_RLIMIT_LAST) == 8);
typedef struct Settings {
/* [Run] */
StartMode start_mode;

View File

@ -43,9 +43,9 @@ typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, co
typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
enum {
SD_RESOLVE_GET_HOST = UINT64_C(1),
SD_RESOLVE_GET_SERVICE = UINT64_C(2),
SD_RESOLVE_GET_BOTH = UINT64_C(3),
SD_RESOLVE_GET_HOST = 1 << 0,
SD_RESOLVE_GET_SERVICE = 1 << 1,
SD_RESOLVE_GET_BOTH = SD_RESOLVE_GET_HOST | SD_RESOLVE_GET_SERVICE,
};
int sd_resolve_default(sd_resolve **ret);

View File

@ -26,7 +26,12 @@ enum Enum {
};
enum BigEnum {
big_enum_value = UINT64_C(-1),
big_enum_value = UINT64_C(1),
};
enum BigEnum2 {
big_enum2_pos = UINT64_C(1),
big_enum2_neg = UINT64_C(-1),
};
int main(void) {
@ -55,6 +60,10 @@ int main(void) {
info(enum Enum);
info(enum BigEnum);
info(enum BigEnum2);
assert_cc(sizeof(enum BigEnum2) == 8);
printf("big_enum2_pos → %zu\n", sizeof(big_enum2_pos));
printf("big_enum2_neg → %zu\n", sizeof(big_enum2_neg));
return 0;
}