Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: hardcoded constants Message-ID: <1988Dec15.190331.2986@utzoo.uucp> Organization: U of Toronto Zoology References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <9134@smoke.BRL.MIL> <1988Dec13.172306.16195@utzoo.uucp> <5146@bsu-cs.UUCP> Date: Thu, 15 Dec 88 19:03:31 GMT In article <5146@bsu-cs.UUCP> dhesi@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@zoo.toronto.edu