diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 14:43:58 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:09:10 +0100 |
commit | 5b57ab6332edc407524a353d3965a4870c33fe00 (patch) | |
tree | 238659ca8e218307fff1476d427c94194bc24fad /toxcore/logger.h | |
parent | aad1e0ad3f96786e0fb10d8dd144e5e6ebe93258 (diff) |
Improve C standard compliance.
- Don't cast between object and function pointers.
- Use standard compliant `__VA_ARGS__` in macros.
- Add explicit `__extension__` on unnamed union in struct (it's a GNU
extension).
- Remove ; after function definitions.
- Replace `const T foo = 3;` for integral types `T` with `enum { foo = 3 };`.
Folding integral constants like that as compile time constants is a GNU
extension. Arrays allocated with `foo` as dimension are VLAs on strictly
compliant C99 compilers.
- Replace empty initialiser list `{}` with zero-initialiser-list `{0}`.
The former is a GNU extension meaning the latter.
- Cast `T*` (where `T != void`) to `void *` in format arguments. While any
object pointer can be implicitly converted to and from `void *`, this
conversion does not happen in variadic function calls.
- Replace arithmetic on `void *` with arithmetic on `char *`. The former
is non-compliant.
- Replace non-`int`-derived types (like `uint16_t`, which is
`short`-derived) in bit fields with `int`-derived types. Using any type
other than `int` or `unsigned int` (or any of their aliases) in bit
fields is a GNU extension.
Diffstat (limited to 'toxcore/logger.h')
-rw-r--r-- | toxcore/logger.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/toxcore/logger.h b/toxcore/logger.h index 88dfd5ac..947b9411 100644 --- a/toxcore/logger.h +++ b/toxcore/logger.h | |||
@@ -61,18 +61,18 @@ void logger_write(Logger *log, LOGGER_LEVEL level, const char *file, int line, c | |||
61 | ...); | 61 | ...); |
62 | 62 | ||
63 | 63 | ||
64 | #define LOGGER_WRITE(log, level, format, ...) \ | 64 | #define LOGGER_WRITE(log, level, ...) \ |
65 | do { \ | 65 | do { \ |
66 | if (level >= MIN_LOGGER_LEVEL) { \ | 66 | if (level >= MIN_LOGGER_LEVEL) { \ |
67 | logger_write(log, level, __FILE__, __LINE__, __func__, format, ##__VA_ARGS__); \ | 67 | logger_write(log, level, __FILE__, __LINE__, __func__, __VA_ARGS__); \ |
68 | } \ | 68 | } \ |
69 | } while (0) | 69 | } while (0) |
70 | 70 | ||
71 | /* To log with an logger */ | 71 | /* To log with an logger */ |
72 | #define LOGGER_TRACE(log, format, ...) LOGGER_WRITE(log, LOG_TRACE , format, ##__VA_ARGS__) | 72 | #define LOGGER_TRACE(log, ...) LOGGER_WRITE(log, LOG_TRACE , __VA_ARGS__) |
73 | #define LOGGER_DEBUG(log, format, ...) LOGGER_WRITE(log, LOG_DEBUG , format, ##__VA_ARGS__) | 73 | #define LOGGER_DEBUG(log, ...) LOGGER_WRITE(log, LOG_DEBUG , __VA_ARGS__) |
74 | #define LOGGER_INFO(log, format, ...) LOGGER_WRITE(log, LOG_INFO , format, ##__VA_ARGS__) | 74 | #define LOGGER_INFO(log, ...) LOGGER_WRITE(log, LOG_INFO , __VA_ARGS__) |
75 | #define LOGGER_WARNING(log, format, ...) LOGGER_WRITE(log, LOG_WARNING, format, ##__VA_ARGS__) | 75 | #define LOGGER_WARNING(log, ...) LOGGER_WRITE(log, LOG_WARNING, __VA_ARGS__) |
76 | #define LOGGER_ERROR(log, format, ...) LOGGER_WRITE(log, LOG_ERROR , format, ##__VA_ARGS__) | 76 | #define LOGGER_ERROR(log, ...) LOGGER_WRITE(log, LOG_ERROR , __VA_ARGS__) |
77 | 77 | ||
78 | #endif /* TOXLOGGER_H */ | 78 | #endif /* TOXLOGGER_H */ |