Path: utzoo!attcan!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Message-ID: <8512@bloom-beacon.MIT.EDU> Date: 18 Dec 88 06:27:44 GMT References: <15852@iuvax.cs.indiana.edu> <883@quintus.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Lines: 27 In article <883@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >henry@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@adam.pika.mit.edu