Re: [dev] [PATCH] [sbase] printf: Avoid casts for better portability

From: FRIGN <dev_AT_frign.de>
Date: Fri, 31 Jan 2014 19:04:46 +0100

On Fri, 31 Jan 2014 18:43:50 +0100
FRIGN <dev_AT_frign.de> wrote:

> Using the C99 PRIu32-macro and %zu-format-specifier increase
> portability and avoid these unnecessary casts.

Argh, I forgot C90 didn't support the z-format-specifier.
So, we won't get around casting len to unsigned long -.-.

Please let me know if I should check the code for more of those cases.

Here's the fixed patch:

diff --git a/cksum.c b/cksum.c
index 25f7274..e762e85 100644
--- a/cksum.c
+++ b/cksum.c
_AT_@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <stdint.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
_AT_@ -106,7 +107,7 @@ cksum(FILE *fp, const char *s)
        for(i = len; i > 0; i >>= 8)
                ck = (ck << 8) ^ crctab[(ck >> 24) ^ (i & 0xFF)];
 
- printf("%lu %lu", (unsigned long)~ck, (unsigned long)len);
+ printf("%"PRIu32" %lu", ~ck, (unsigned long)len);
        if(s != NULL)
                printf(" %s", s);
        putchar('\n');

-- 
FRIGN <dev_AT_frign.de>
Received on Fri Jan 31 2014 - 19:04:46 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 31 2014 - 21:12:07 CET