ID Number: Q34409
5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a
MS-DOS | OS/2
buglist5.10 buglist6.00 buglist6.00a buglist6.00ax fixlist7.00
Summary:
SYMPTOMS
If the following conditions are true:
- Function "x" is given static storage
- There are two functions, y() and z(), calling y()
-or-
There is only one function calling it, but the /Za is used
- x() is prototyped inside y() and z() (block scope)
Microsoft C 5.1 generate the following output if /Ze is used:
C2129: static function 'x' not found
C4074: function given file scope
C4074: function given file scope
Microsoft C 5.1 generates the following if /Za is used:
C2129: static function 'x' not found
C2129: static function 'x' not found
Microsoft C 6.0, 6.0a, 6.0ax will generate the following output if
/Ze is used:
C2129: static function 'x' not found
C4001: function given file scope
C4001: function given file scope
However, Microsoft C 6.0, 6.0a, 6.0ax generate the correct output
if /Za is used:
C2201: must be extern
C2201: must be extern
CAUSE
ANSI does not permit a function prototype that has block scope to
have an explicit specifier other than extern. C4074 and C4001,
which indicate that the function has been given file scope to
remedy the situation, are warnings that are given if compiling with
/Ze. Error C2201 is generated if /Za is used, to indicate that the
function must be defined with extern as well. The generation of the
C2129 error is incorrect.
STATUS
Microsoft has confirmed this to be a problem in C version 5.1,
6.0, 6.0a, and 6.0ax. This problem was corrected in C/C++ version
7.0.
More Information:
C/C++ version 7.0 correctly gives the C4001 warning with /Ze, and
gives "C2201: cannot export static declarations" with /Za.
The sample program below demonstrates the problem. The problem does
not occur if any of the following are true:
- y() does not call x(), and /Ze is used
-or-
- The function prototypes for x() are given file scope
Sample Code:
------------
/* Compile options needed: /Ze -or- /Za, /W3 (5.1) or /W4 (> 5.1)
*/
#include <stdio.h>
void y( void );
void y( )
{
static void x( char c ); /* C4074 / C4001 with /Ze only */
/* C 6.0: C2201 with /Za */
char c = 'y';
x( c ) ; /* C2129: C 5.1; C 6.0 with /Ze only */
}
void z( void );
void z( )
{
static void x( char c ); /* C4074 / C4001 with /Ze only */
/* C 6.0: C2201 with /Za */
char c = 'z';
x( c ); /* C 5.1: C2129 with /Za only */
}
static void x( char c )
{
printf( "%c\n", c );
}