hardcoded constants
Henry Spencer
henry at utzoo.uucp
Fri Dec 16 05:03:31 AEST 1988
In article <5146 at bsu-cs.UUCP> dhesi at bsu-cs.UUCP (Rahul Dhesi) writes:
>>The policy we try to follow is that if you must hard-code a constant,
>>then it must be accompanied by a comment explaining why that particular
>>number is there.
>
>A suggestion: If you want to hard-code a constant, use a #define
>anyway...
Trouble is, often it's almost impossible to devise a meaningful name.
I'm not talking about hard-coding things like choice of control characters,
but about things like (in a function to concatenate two strings with a
'/' in between):
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?
--
"God willing, we will return." | Henry Spencer at U of Toronto Zoology
-Eugene Cernan, the Moon, 1972 | uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list