New 'n' Improved comp.lang.c FAQ List

Jo Are Rosland jar at ifi.uio.no
Tue Apr 2 23:03:47 AEST 1991


In article <31946 at shamash.cdc.com> bls at u02.svl.cdc.com (Brian Scearce) writes:

   grover at big-joe.cs.unlv.edu (Kevin Grover) writes:
   > Apparently non-obvious April Fool's Day bogus account posts:

   Almost, but not quite, Mr. Grover.  The *really* correct version of this:

	   char *itoa(int i)
	     {
	       static char retbuf[5];         /* biggest int: 32768 */
	       sprintf(retbuf, "%d", i);
	       return retbuf;
	     }

Not to be picky, but

	char *itoa(int i)
	{
	    static char retbuf[7];	/* biggest int: 32767 */
	    sprintf(retbuf, "%d", i);
	    return retbuf;
	}

is really, *really* correct, provided int is stored two's-complement
in 16 bits.  FLAME SHIELD: This of course is not a portable
assumption, and the whole function is redundant, and it's interface
stinks, and the original function at least had some value as comic
relief whereas this one has none.

But all of this is probably getting rather silly, and not at all as
entertaining as the original posting, sorry ;-(
--
Jo Are Rosland
jar at ifi.uio.no



More information about the Comp.lang.c mailing list