Microsoft KB Archive/66776

= INFO: No Warning If Parameter Redeclared Using the Old Style =

Q66776

-

The information in this article applies to:


 * The Microsoft C/C++ Compiler (CL.EXE)
 * Microsoft C for MS-DOS, versions 6.0, 6.0a, 6.0ax
 * Microsoft C for OS/2, versions 6.0, 6.0a
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5
 * Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 4.0, 5.0, 6.0

-

SUMMARY
In situations where the so-called &quot;old-style&quot; or &quot;K&R-type&quot; function declarations are used, the C compiler does 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.

MORE INFORMATION
The following code sample demonstrates this redeclaration problem:

Sample Code
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:

warning C4131: 'func1' : uses old-style 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 code given above is invalid in a C++ module (.CPP extension). Additional query words: 8.00 8.00c 9.00

Keywords : kbCompiler kbVC100 kbVC150 kbVC200 kbVC400 kbVC500 kbVC600

Issue type : kbinfo

Technology :

Last Reviewed: July 30, 2001

-

[mailto:MSDN@MICROSOFT.COM Send feedback to Microsoft]

© 2002 Microsoft Corporation. All rights reserved.