Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!haven!vrdxhq!daitc!bms-at!stuart From: stuart@bms-at.UUCP (Stuart Gathman) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Summary: And get it wrong to boot . . . Message-ID: <140@bms-at.UUCP> Date: 22 Dec 88 02:53:46 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <2636@m2-net.UUCP> Organization: Business Management Systems, Inc., Fairfax, VA Lines: 19 In article <2636@m2-net.UUCP>, remmers@m-net.UUCP (John H. Remmers) writes: > The space requirement for a string concatenation is a frequently-needed > value; it's worth having a macro to represent it: > #define Catspace(s,t) (strlen(s) + strlen(t) + 1) > In terms of this, the malloc() call can be written: > foo = malloc(Catspace(s,t) + sizeof('/')); > thus making it explicit that you're concatenating two strings and > allocating one more byte for an extra character. Readability is > improved, and the question of naming the "2" never comes up. Of course, this is incorrect since sizeof('/') is 2 or 4 depending on your machine. But the concept is good . . . -- Stuart D. Gathman <..!{vrdxhq|daitc}!bms-at!stuart>