# HG changeset patch # User Markus Bröker # Date 1275945647 -7200 # Node ID 54a04f5f141d6ece524c845504567e5a5c769ac6 # Parent b5ad49852adc8f59dc3e089ebcdf119d80cc421e 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 diff --git a/getbits.c b/getbits.c --- a/getbits.c +++ b/getbits.c @@ -4,12 +4,12 @@ * */ #include -#include +#include #include -#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; }