hardcoded constants

Henry Spencer henry at utzoo.uucp
Wed Dec 14 03:23:06 AEST 1988


In article <9134 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>>How much hard-coding is too much?
>
>Almost any is too much.  It is proper to use explicit constants when it
>is clear what they mean and that they can never need to be changed.  For
>example, assigning 0 or 1 to initialize a counter is proper.  Assuming
>that 03 is always the right character code for a keyboard interrupt
>character (i.e. ASCII ctrl-C) is not proper.

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.
-- 
SunOSish, adj:  requiring      |     Henry Spencer at U of Toronto Zoology
32-bit bug numbers.            | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list