KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q66776: No Warning for Redeclared Parameter on Old-Style Declarations

Article: Q66776
Product(s): See article
Version(s): 6.00 6.00a | 6.00 6.00a
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | S_QUICKC | mspl13_c
Last Modified: 10-NOV-1990

In situations where the so-called "old-style" or "K&R-type" function
declarations are used, the C compiler will not generate a warning when
formal parameters are declared twice, even if they are redeclared with
different types. This is expected behavior because one of the
declarations is ignored when this type of function declaration is
used. If ANSI-style, prototyped function declarations are used, a
warning will be generated for any redeclarations.

The following code sample demonstrates this redeclaration problem:

   int func1(x, y)
   int x;
   long y;
   float x;       /* x is redeclared here, but no warning is given */
   {
      return (int)(x + y);
   }

Even when this code is compiled at warning level 4 (/W4), the
redeclaration of x does not generate any warnings -- the compiler only
warns that func1() is using an old-style function declarator.

Microsoft is committed to the ANSI standard and no diagnostic-message
changes are planned to accommodate inconsistencies arising from use of
the old declaration style. The ANSI specification, in section 3.9.5,
page 96, states the following:

   The use of function definitions with separate parameter identifier
   and declaration lists (not prototype-format parameter type and
   identifier declarators) is an obsolescent feature.

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.