[comp.lang.c] comments

dg@lakart.UUCP (David Goodenough) (01/05/89)

From article <34@datcon.UUCP>, by sar@datcon.UUCP (Simon A Reap):
K In article <1988Dec21.133910.23182@ateng.ateng.com> chip@ateng.ateng.com
i 						    (Chip Salzenberg) writes:
s>According to henry@utzoo.uucp (Henry Spencer):
s>>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,
a>>but about things like (in a function to concatenate two strings with a
s>>'/' in between):
s>>	foo = malloc(strlen(a)+strlen(b)+2);	/* 2 for '/' '\0' */
 >Not hard:
i>	foo = malloc(strlen(a)+sizeof("/")+strlen(b));
n 
e Ah, but if we want to concatenate more strings, don't we need something
w like....
s 
  #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);

Forgive my ignorance, but isn't this what comments were invented for?

	foo = malloc(strlen(a)+strlen(b)+2);	/* 2 for '/' '\0' */
						^^^^^^^^^^^^^^^^^^^^

or:

	foo = malloc(strlen(a) + strlen(b) + strlen(c) + 3);
						/* 3 for '/', '/', '\0' */
-- 
	dg@lakart.UUCP - David Goodenough		+---+
							| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp@xait.xerox.com		  	  +---+