hardcoded constants
Arthur David Olson
ado at elsie.UUCP
Thu Dec 29 08:45:47 AEST 1988
> > . . .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 at ncifcrf.gov ADO is a trademark of Ampex.
More information about the Comp.lang.c
mailing list