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

Brian Scearce bls at u02.svl.cdc.com
Tue Apr 2 13:03:43 AEST 1991


grover at big-joe.cs.unlv.edu (Kevin Grover) writes:
> Apparently non-obvious April Fool's Day bogus account posts:
>> Q: Why doesn't this function work:
>>
>>         itoa(int i)
>>         {
>>         char retbuf[5];         /* biggest int: 32769 */
>>         sprintf("%d", retbuf, i);
>>         return retbuf;
>>         }
>>

>	A correct version of this program is:
>        char *itoa(int i)
>          {
>            static char retbuf[5];         /* biggest int: 32769 */
>            sprintf(retbuf, "%d", i);
>            return retbuf;
>          }

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;
          }

If you are going to put in comments, you should make sure they're
correct.  Actually, I delete all my comments from production code,
for efficiency.  Although the next release of my compiler is
suppossed to emit no-ops for comments, I can't afford to upgrade
right now.

>> Q: Which is more efficient, i = i + 1 or i = 1 + i ?
>> A: [ intrinsic __inc is suggested ]

>	Why not just use the ++ operator??? (as in i++, or ++i)   Any decent
>	compiler should use the ML increment function if your machine has one.

He probably just forgot.  Programmers aren't perfect, and having
so many operators in C just makes the situation worse.  A meaningful
name like __inc() is better.  If the programmer is one of the ones
smart enough to remember the C build-in operator, then he can write
a define like:

#define __inc(x) ++(x)

So nothing is lost.  Personally, I avoid ++: it makes me think of
George Orwell.

 ++good; /* Assign 0x7c0 to good */

>> Q: What's the best indentation and brace placement style?
>> A: Don't bother indenting [...]

>	What do you mean, DON'T BOTHER INDENTING????

Like comments, whitespace should be removed for efficiency.  If
you are one of the lucky few that has a compiler that can handle
whitespace efficiently, count your blessings, but don't ask the
rest of us to mutate our code to fit your compiler.

>	Is this a joke?  Was this whole post a joke?

That would be irresponsible.

Except on April 1.

To the original author: you should have posted from a real account.
I wanted to thank you without wasting bandwidth.  The N&I FAQ is
going up on my office door.

--
     Brian Scearce (bls at robin.svl.cdc.com  -or-  robin!bls at shamash.cdc.com)
    "Don't be surprised when a crack in the ice appears under your feet..."
 Any opinions expressed herein do not necessarily reflect CDC corporate policy.



More information about the Comp.lang.c mailing list