hardcoded constants

Stuart Gathman stuart at bms-at.UUCP
Thu Dec 22 12:53:46 AEST 1988


In article <2636 at m2-net.UUCP>, remmers at 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	<stuart at bms-at.uucp>
			<..!{vrdxhq|daitc}!bms-at!stuart>



More information about the Comp.lang.c mailing list