hardcoded constants
Simon A Reap
sar at datcon.UUCP
Wed Jan 4 00:19:36 AEST 1989
In article <1988Dec21.133910.23182 at ateng.ateng.com> chip at ateng.ateng.com
(Chip Salzenberg) writes:
>According to henry at 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 at datcon.co.uk, or ...!mcvax!ukc!pyrltd!datcon!sar
More information about the Comp.lang.c
mailing list