ANSI Standards

Stanley Friesen sarima at tdatirv.UUCP
Sun Apr 14 02:17:26 AEST 1991


In article <104 at hdwr1.medar.com> jseymour at medar.com (James Seymour) writes:
>1) We've been using the K&R format for function definitions, while the
>   new ANSI format is like the Pascal format (for example).  The K&R
>   Second Edition states that the original K&R form will be supported
>   at least during the "transition period".  Does the ANSI standard
>   eliminate the original K&R format (eventually)?  Even if it doesn't,
>   does it look like that's the way "everybody" will be doing it in the
>   future?  Btw: I've yet to see code from any source using the new
>   ANSI format, other than examples in some texts.

The old style of function declarations is not eliminated in the ANSI
standard but it *is* depreciated.  That is it is listed as an obsolete
feature subject to deletion in some unspecified future version of the standard.
[The anticipated date for the next version is often cited as 2001].

Thus everyone *will* be shifting to using the new style function declarations,
but *very* slowly, since many existing compilers do no support them, and
many non-ANSI compilers will continue to be used for many years to come.
Many developers are using a hack involving #ifdef to provide both styles
in the same source code.

>2) Parenthesis are not required for return statements, but according to
>   the Second Edition K&R work, they are, and will remain, acceptable.
>   I *have* seen lots of code where the parens are not used.  Does this
>   seem to be the way most folks are heading?  If so, why?

The parentheses have not been required for a very long time. (Not even when
K&R I was published).  The value of a return statement is any expression,
and since an expression in parentheses is always equivalent to the same
expression without parentheses, they are and will remain optional in this
context.

>(Personally, I prefer the original K&R forms for both of these, as do
> most of the engineers here).

The use of parentheses around return values is a style matter, and is of
little real importance to code quality.  It should be left to the individual
programmer.

The new style function declarations are a vast improvement over the old,
since they allow more exact type checking by the compiler.  Thus they
are to be prefered if your compiler is ANSI.

The most effective way to use the new style declarations is to place a
prototype for every externally visible function into some header file
that is included everywhere the function is used and also where it is
defined.   This provides maximum type safety.
-- 
---------------
uunet!tdatirv!sarima				(Stanley Friesen)



More information about the Comp.lang.c mailing list