From 5b57ab6332edc407524a353d3965a4870c33fe00 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 5 Sep 2016 14:43:58 +0100 Subject: 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. --- testing/dns3_test.c | 2 +- testing/misc_tools.c | 2 +- testing/nTox.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'testing') diff --git a/testing/dns3_test.c b/testing/dns3_test.c index 063ea8c7..830ecfd8 100644 --- a/testing/dns3_test.c +++ b/testing/dns3_test.c @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) return -1; } - uint8_t buffer[512] = {}; + uint8_t buffer[512] = {0}; int r_len = recv(sock, buffer, sizeof(buffer), 0); if (r_len < (int)p_len) { diff --git a/testing/misc_tools.c b/testing/misc_tools.c index de246d82..b667f991 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -85,4 +85,4 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) } return argvoffset; -}; +} diff --git a/testing/nTox.c b/testing/nTox.c index ec6b152c..fcfbe004 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -57,7 +57,7 @@ uint8_t flag[HISTORY]; char input_line[STRING_LENGTH]; /* wrap: continuation mark */ -const size_t wrap_cont_len = 3; +enum { wrap_cont_len = 3 }; const char wrap_cont_str[] = "\n+ "; #define STRING_LENGTH_WRAPPED (STRING_LENGTH + 16 * (wrap_cont_len + 1)) -- cgit v1.2.3