hardcoded constants
Steve Summit
scs at adam.pika.mit.edu
Sun Dec 18 16:27:44 AEST 1988
In article <883 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>henry at utzoo.uucp (Henry Spencer) writes:
>>- foo = malloc(strlen(a)+strlen(b)+2); /* 2 for '/' '\0' */
>>-Now, what's a good name for that "2", and how does naming it improve
>>-readability?
>
>I recently had a very similar problem. A *superb* "name" for that 2 is
> sizeof "/"
Was this suggestion supposed to include a :-) ? sizeof("/") is a
very poor substitute, in this case: it gets the right answer for
the wrong reason. (The '\0' the compiler counts in the string
constant "/" has little to do with the one which will be added
to the final, concatenated string.)
I once scratched my head over
kill(HUP, 1);
in a program which had modified /etc/ttys and wanted to tell
/etc/init (process 1) to re-read it. (This is more of a
unix-wizards than an info-c topic.) Funny thing: man 2 kill
says it's kill(pid, signal), and yet the code worked just fine.
(Spoiler: HUP just happens to be 1).
Steve Summit
scs at adam.pika.mit.edu
More information about the Comp.lang.c
mailing list