On Tue, 14 Dec 2004 12:14:26 UTC, sathya <sa****@nomail.com> wrote:
I have come across the following code which treys to implement the
strcat function. It may
be wrong or correct, but it is using integer zero instead of
appending the C string terminator '\0'.
'\0' is commonly used to document inline that you means a (char)0.
0, char(0), '\0' have always the same meaning but
0 requires from the reader to see that you assigns/compares a char.
The reader has to think an extra step to see that you means a char.
char(0): casting is always an dangerous option, requiring rethinking
it if it does really what you needs and means, so avoiding casts
whenever possible makes the code more readable.
'\0' is documenting that you speaks about chars, not ints. It is more
for the reader than for the compiler.
So both, 0 and '\0' are commonly used to address a null value as char,
whereas '\0' is more documentative but costs 3 extra typings. C
programmers are often sluggish, so they avoid typing as they can.
--
Tschau/Bye
Herbert
Visit
http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!