Null revisited (briefly)

Norman Diamond diamond at diamond.csl.sony.junet
Mon Feb 20 13:57:55 AEST 1989


In article <102 at servio.UUCP> penneyj at servio.UUCP (D. Jason Penney) writes:
[for null-terminating a C string]

>char aString[20];
>aString[0] = '\0';

Yes, this is fine.

>'x' is a literal of type char.  Thus, '\0' is the char with value 0,
>which is really what was intended here.

In fact, 'x' is a literal of type int, and '\0' is the same as 0.

>When you assign an int or a pointer to a character, the reader ends
>up wondering if the type mismatch is unintentional.

When you assign 'x' to a character, you are assigning an int to a
character.  The reader knows that the type mismatch was intentional.
But readers who do not understand the type mismatch often make
different errors, where results are counter-intuitive.
--
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp at relay.cs.net)
  The above opinions are my own.   |  Why are programmers criticized for
  If they're also your opinions,   |  re-inventing the wheel, when car
  you're infringing my copyright.  |  manufacturers are praised for it?



More information about the Comp.lang.c mailing list