Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!iuvax!bsu-cs!dhesi From: dhesi@bsu-cs.UUCP (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Message-ID: <5146@bsu-cs.UUCP> Date: 14 Dec 88 16:51:28 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <9134@smoke.BRL.MIL> <1988Dec13.172306.16195@utzoo.uucp> Reply-To: dhesi@bsu-cs.UUCP (Rahul Dhesi) Organization: CS Dept, Ball St U, Muncie, Indiana Lines: 27 In article <1988Dec13.172306.16195@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) 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: check_break() { #define CTRL_C 3 /* ASCII control C */ if (keyscan() == CTRL_C) ... } A well-chosen name will make the code understandable. Any additional information about the hard-coded value can be in a comment to the #define itself. Scanning the source for all #defines will let you locate all hard-coded constants with some confidence. So I find the above code fragment preferable to the following: check_break() { if (keyscan() == 3) /* check for ASCII control C */ ... } -- Rahul Dhesi UUCP: !{iuvax,pur-ee}!bsu-cs!dhesi