Path: utzoo!attcan!uunet!husc6!mailrus!uflorida!haven!cvl!elsie!ado From: ado@elsie.UUCP (Arthur David Olson) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Summary: When in doubt, do without Message-ID: <8597@elsie.UUCP> Date: 28 Dec 88 22:45:47 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <1988Dec26.021757.15813@ziebmef.uucp> Organization: NIH-LEC, Bethesda, MD Lines: 16 > > . . .the malloc() call can be written: > > foo = malloc(Catspace(s,t) + sizeof('/')); > > For true safety, I'd write this as > foo = malloc(Catspace(s,t)*sizeof(char) + sizeof('/')); What we write in this neck of the woods is foo = ecpyalloc(s); foo = ecatalloc(foo, t); where "ecpyalloc" sets foo pointing to an allocated copy of s (a la "AllocCpy" in the 2.11.14 news software) and "ecatalloc" sets foo pointing to a reallocation of foo with t catenated. This avoids the need for a hardcoded constant entirely; since you don't use one, you can't get its value wrong. -- Arthur David Olson ado@ncifcrf.gov ADO is a trademark of Ampex.