以下代码编译良好:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
extern int errno ;
int main ( void )
{
FILE *fp;
int errnum;
fp = fopen ("testFile.txt", "rb");
if ( fp == NULL )
{
errnum = errno;
fprintf( stderr, "Value of errno: %d\n", errno );
perror( "Error printed by perror" );
fprintf( stderr, "Error opening file: %s\n", strerror( errnum ) );
exit( 1 );
}
fclose ( fp );
}
但我不能编译它:
gcc-8 -Wall -Wextra -Werror -Wstrict-prototypes
我得到以下信息:
program.c:6:1: error: function declaration isn’t a prototype [-Werror=strict-prototypes]
extern int errno ;
^~~~~~
cc1: all warnings being treated as errors
我怎样才能避免/解决这个问题?我需要这个编译器标志-Wstrict-prototypes