sizeof(char)

Doug Gwyn gwyn at brl-smoke.ARPA
Tue Nov 11 23:05:07 AEST 1986


In article <5355 at brl-smoke.ARPA> I wrote:
>	use of sizeof"string_constant" instead of
>	strlen("string_constant")+1 : occurs in about 10 places (I had to
>	find all these once, since an older Gould compiler insisted that
>	sizeof"string_constant"==sizeof(char *) .)

It occurs to me that if I don't add the following, someone will
undoubtedly pick up on a point that would result in even more net traffic:

	I deliberately didn't show the simpler, more efficient fix of
	using sizeof"string_constant"/sizeof(char) because that wasn't
	helpful for the Gould compiler's problem.  However, if 	one's
	compiler can be counted on to work, this latter is a much better
	fix.  Both approaches are also correct for pre-X3J11 C compilers.
	The important thing to notice is that you can prepare your code
	NOW for any possible future transition to a compiler that doesn't
	assume sizeof(char)==1.  I highly recommend this whether or not
	my proposal is adopted, since it helps to maintain the CONCEPTUAL
	distinction between characters and memory storage unit cells,
	much as I recommend writing C code AS THOUGH the C language
	(like Algol) distinguished between Booleans and ints.  We
	shouldn't have to argue the merits of data abstraction here,
	since that is taught in basic computer science courses (according
	to what I hear -- there weren't any such courses when I first got
	into this business, since we were busy inventing the discipline).



More information about the Comp.lang.c mailing list