typedefs, etc.

gwyn%brl-vld at sri-unix.UUCP gwyn%brl-vld at sri-unix.UUCP
Wed Jan 4 05:32:13 AEST 1984


From:      Doug Gwyn (VLD/VMB) <gwyn at brl-vld>

I think one's programming style is improved if he carefully maintains
the distinction between boolean data and integer data, even though the
C language does not.  Examples:

	if ( p != NULL )
		fputs( p, stdout );
rather than
	if ( p )
		fputs( p, stdout );

	while ( *p != '\0' )
		putchar( *p++ );
rather than
	while ( *p )
		putchar( *p++ );

Although the above alternatives lead to identical machine code and are
not obviously superior taken out of context, they say precisely what is
intended without requiring the reader to remember C-specific language
peculiarities.  I find that careful attention to data typing, of which
boolean-vs-integer is a small part, contributes to error-free coding.



More information about the Comp.unix mailing list