hardcoded constants

Mark A Terribile mat at mole-end.UUCP
Mon Dec 19 07:31:37 AEST 1988


>      [But how about] about things like (in a function to concatenate
>      two strings with a '/' in between):
> 
> 	   foo = malloc(strlen(a)+strlen(b)+2);	/* 2 for '/' '\0' */
> 
> You are right.  This is a valid exception to my suggestion, and it had
> not occurred to me.

Well, there is a way, although it's a little wordy and I don't know if I'd
do it myself.

	foo = malloc( strlen( a ) + strlen( b ) + 2 * sizeof( char ) );

You may still have to note that the chars are '/' and null.
-- 

(This man's opinions are his own.)
>From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list