Adjusted to show side effects and their handling
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Mon, 07 Jun 2010 23:20:47 +0200
changeset 132 54a04f5f141d
parent 131 b5ad49852adc
child 133 f46f9606dbfb
Adjusted to show side effects and their handling When dealing with static buffers, successive calls point to the same memory location and overwrite formers ones... committer: Markus Bröker <mbroeker@largo.homelinux.org>
getbits.c
--- a/getbits.c
+++ b/getbits.c
@@ -4,12 +4,12 @@
  *
  */
 #include <stdio.h>
-#include <limits.h>
+#include <stdlib.h>
 #include <string.h>
 
-#define BITS 64
+#define BITS 8
 
-char *getbits (unsigned long long what)
+char *getbits (unsigned int what)
 {
     static char byte[BITS + 1];
 
@@ -29,16 +29,11 @@
 int main (void)
 {
     unsigned int i;
-    for (i = 1; i < 16; i++)
-        printf ("%s\n", getbits (i));
+    char *s = strdup (getbits (255));
 
-    printf ("%s\n", getbits (USHRT_MAX));
-    printf ("%s\n", getbits (UINT_MAX));
-    printf ("%s\n", getbits (ULONG_MAX));
-
-#ifdef ULLONG_MAX
-    printf ("%s\n", getbits (ULLONG_MAX));
-#endif
+    for (i = 240; i < 255; i++)
+        printf ("%s %s %s %s (%d)\n", s, s, s, getbits (i), i);
+    free (s);
 
     return 0;
 }