Path: utzoo!attcan!uunet!husc6!ukma!rutgers!att!ulysses!attibr!vch From: vch@attibr.UUCP (Vincent C. Hatem) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Message-ID: <77@attibr.UUCP> Date: 22 Dec 88 20:30:39 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <1988Dec21.133910.23182@ateng.ateng.com> Organization: AT&T International, Basking Ridge, NJ Lines: 33 In article <1988Dec21.133910.23182@ateng.ateng.com>, chip@ateng.ateng.com (Chip Salzenberg) writes: ] According to henry@utzoo.uucp (Henry Spencer): ] >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' */ ] ] Not hard: ] ] foo = malloc(strlen(a)+sizeof("/")+strlen(b)); ] ] -- ] Chip Salzenberg or ] A T Engineering Me? Speak for my company? Surely you jest! ] "It's no good. They're tapping the lines." Right, chip. Last I heard sizeof("/") == sizeof(char *) - which is almost never 2, and NEVER portable. How about the more accurate: foo = malloc(strlen(a)+strlen(b)+(2*sizeof(char))); -- Vincent C. Hatem | att ---->\ (available from any AT&T International | ulysses ->\ Action Central site) International Operations Technical Support | bellcore ->\___ !attibr!vch 1200 Mt Kemble Ave, Basking Ridge, NJ 07920 | (201) 953-8030