diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-16 20:11:14 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-16 20:18:25 +0100 |
commit | 6dc431b0c970f9b5344c40d0d608232e2b63549a (patch) | |
tree | f97e106276e301da29a2f7d6e246071688315f95 | |
parent | b8c677a0eb7c11f5ee084947188645d585c917e9 (diff) | |
download | NetworkManager-6dc431b0c970f9b5344c40d0d608232e2b63549a.tar.gz |
shared: move definition of "bool" to nm-macros-internal.h
"nm-default.h" should only include all the relevant header files based
on NETWORKMANAGER_COMPILATION. It should not contain definitions on
it's own.
Move the definition of "bool" to "nm-macros-internal.h".
-rw-r--r-- | shared/nm-default.h | 47 | ||||
-rw-r--r-- | shared/nm-macros-internal.h | 47 |
2 files changed, 47 insertions, 47 deletions
diff --git a/shared/nm-default.h b/shared/nm-default.h index 72b74a5493..a528e56295 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -74,51 +74,4 @@ /*****************************************************************************/ -/** - * The boolean type _Bool is C99 while we mostly stick to C89. However, _Bool is too - * convinient to miss and is effectively available in gcc and clang. So, just use it. - * - * Usually, one would include "stdbool.h" to get the "bool" define which aliases - * _Bool. We provide this define here, because we want to make use of it anywhere. - * (also, stdbool.h is again C99). - * - * Using _Bool has advantages over gboolean: - * - * - commonly _Bool is one byte large, instead of gboolean's 4 bytes (because gboolean - * is a typedef for gint). Especially when having boolean fields in a struct, we can - * thereby easily save some space. - * - * - _Bool type guarantees that two "true" expressions compare equal. E.g. the follwing - * will not work: - * gboolean v1 = 1; - * gboolean v2 = 2; - * g_assert_cmpint (v1, ==, v2); // will fail - * For that, we often to use !! to coerce gboolean values to 0 or 1: - * g_assert_cmpint (!!v2, ==, TRUE); - * With _Bool type, this will be handled properly by the compiler. - * - * - For structs, we might want to safe even more space and use bitfields: - * struct s1 { - * gboolean v1:1; - * }; - * But the problem here is that gboolean is signed, so that - * v1 will be either 0 or -1 (not 1, TRUE). Thus, the following - * fails: - * struct s1 s = { .v1 = TRUE, }; - * g_assert_cmpint (s1.v1, ==, TRUE); - * It will however work just fine with bool/_Bool while retaining the - * notion of having a boolean value. - * - * Also, add the defines for "true" and "false". Those are nicely highlighted by the editor - * as special types, contrary to glib's "TRUE"/"FALSE". - */ - -#ifndef bool -#define bool _Bool -#define true 1 -#define false 0 -#endif - -/*****************************************************************************/ - #endif /* __NM_DEFAULT_H__ */ diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index 4d802746ba..fb8ab2ceac 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -446,4 +446,51 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro) { /*****************************************************************************/ +/** + * The boolean type _Bool is C99 while we mostly stick to C89. However, _Bool is too + * convinient to miss and is effectively available in gcc and clang. So, just use it. + * + * Usually, one would include "stdbool.h" to get the "bool" define which aliases + * _Bool. We provide this define here, because we want to make use of it anywhere. + * (also, stdbool.h is again C99). + * + * Using _Bool has advantages over gboolean: + * + * - commonly _Bool is one byte large, instead of gboolean's 4 bytes (because gboolean + * is a typedef for gint). Especially when having boolean fields in a struct, we can + * thereby easily save some space. + * + * - _Bool type guarantees that two "true" expressions compare equal. E.g. the follwing + * will not work: + * gboolean v1 = 1; + * gboolean v2 = 2; + * g_assert_cmpint (v1, ==, v2); // will fail + * For that, we often to use !! to coerce gboolean values to 0 or 1: + * g_assert_cmpint (!!v2, ==, TRUE); + * With _Bool type, this will be handled properly by the compiler. + * + * - For structs, we might want to safe even more space and use bitfields: + * struct s1 { + * gboolean v1:1; + * }; + * But the problem here is that gboolean is signed, so that + * v1 will be either 0 or -1 (not 1, TRUE). Thus, the following + * fails: + * struct s1 s = { .v1 = TRUE, }; + * g_assert_cmpint (s1.v1, ==, TRUE); + * It will however work just fine with bool/_Bool while retaining the + * notion of having a boolean value. + * + * Also, add the defines for "true" and "false". Those are nicely highlighted by the editor + * as special types, contrary to glib's "TRUE"/"FALSE". + */ + +#ifndef bool +#define bool _Bool +#define true 1 +#define false 0 +#endif + +/*****************************************************************************/ + #endif /* __NM_MACROS_INTERNAL_H__ */ |