Re: Kernighan and Ritchie notation contentions

Subject: Re: Kernighan and Ritchie notation contentions
From: Shakespeare's Monkey <CARL_M1 -at- VERIFONE -dot- COM>
Date: Mon, 31 Jul 1995 11:07:48 -1000

Eric Schieler inquires about Kernighan and Ritchie notation contentions.

[This should amplify the "Does a Tech Writer need to know C" thread.]

Kernighan and Ritchie most likely refers to the initial documentation
for the C Programming Language (aka K&R C). K&R C was the de facto
language standard for C as documented in _The C Programming Language_
by Brian Kernighan and Dennis Ritchie of Bell Labs, Prentice Hall:New
Jersey (First Edition, 1978, ISBN 0-13-110163-3

The "contention" (if contention is indeed the issue, and not convention)
is between the First and Second Editions. The Second Edition,
ISBN 0-13-110370-8 (pbk.)) anticipated the ANSI Standard for the C
Programming Language (ANSI: X3J11) which was still a Draft in 1988.
(There is little difference between the 1988 Draft and the final standard).

The First Edition was until then a de facto standard. Appendix C of the
Second Edition lists the changes from the First to the Second editions.
Most are enhancements and are not critical to a Tech. Writer. The change
most apparent to C documentation is in function prototyping.

In K&R C, a function definition and its argument declarations are
divided into sections:

int routine(input, output, buffer_length)

char * input;
char * output;
int buffer_length;

{

routine operations

}

(See K&R First Edition, Section 1.7, page 22)

In ANSI C (and K&R Second Edition), a function protoype is made on
one line:


int routine(char * input, char * output, int buffer_length)

{

routine operations

}

[Note: the initial declaration is a statement terminating with a
semicolon, while the actual function definition (with braces, as above)
does not terminate with a semicolon.]

(See K&R Second Edition, Section 1.7, page 24 or the ANSI Standard
Section 3.5)

ANSI C includes a macro to assist the compiler in deciding whether to
handle the source code as K&R or ANSI. (The compiler will probably also
use a switch as well.) The macro is "__STD__" and is used with an
"#if defined" directive. Thus, a source code file written for either
K&R or C compilation would read:

#if defined __STDC__

int routine(char * input, char * output, int buffer_length)

#else

int routine(input, output, buffer_length)

char * input;
char * output;
int buffer_length;

#endif

Some lint programs can also check for K&R or ANSI C and a programmer
may OR a lint directive:
#if defined (__STDC__) || (_lint)

You should consult the documentation of the compiler your developers are
using. However, the point of most of the above to keep the source code
as portable as possible (i.e., if your company decides to use a different
compiler, or compile to another platform, the source code will not need
to be revised).

Carl Millholland


Previous by Author: Quality Docs and ISO 9000
Next by Author: Re: Kernighan and Ritchie notation contentions
Previous by Thread: Kernighan and Ritchie notation contentions
Next by Thread: Re: Kernighan and Ritchie notation contentions


What this post helpful? Share it with friends and colleagues:


Sponsored Ads