Path: utzoo!attcan!uunet!mcvax!ukc!pyrltd!datcon!sar From: sar@datcon.UUCP (Simon A Reap) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Message-ID: <34@datcon.UUCP> Date: 3 Jan 89 14:19:36 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <9134@smoke.BRL.MIL> <1988Dec13.172306.16195@utzoo.uucp> <5146@bsu-cs.UUCP> <1988Dec15.190331.2986@utzoo.uucp> <1988Dec21.133910.23182@ateng.ateng.com> Reply-To: sar@datcon.co.uk (Simon A Reap) Organization: Data Connection Limited, Enfield, Middlesex, UK Lines: 27 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)); Ah, but if we want to concatenate more strings, don't we need something like... #define TO_CAT_3_STRINGS (-1) #define TO_CAT_4_STRINGS (-2) foo = malloc(strlen(a)+sizeof("/")+strlen(b)+sizeof("/")+ strlen(c)+TO_CAT_3_STRINGS); foo = malloc(strlen(a)+sizeof("/")+strlen(b)+sizeof("/")+ strlen(b)+sizeof("/")+strlen(c)+TO_CAT_4_STRINGS); with, of course, negative constants to *really* confuse the beginner :-) (Yes, I know you could have a single 'sizeof("//")' or sizeof("///") as required, but that's not really the point, is it?) -- Enjoy, yerluvinunclesimon Opinions are mine - my cat has her own ideas Reach me at sar@datcon.co.uk, or ...!mcvax!ukc!pyrltd!datcon!sar