我正在尝试编译一些 C 代码(写于 1993 年)并消除了一些小皱纹,但被困在一个(15/16 对象编译与 2 个小调整)。这是向我发送错误的代码:
#include "diagmesg.h"
#include <string.h>
#include <stdlib.h>
/* Definition of global variables */
FILE * error_fp = stderr;
这是diagmesg.h:
#ifndef DIAGMESG_H
#define DIAGMESG_H
#include <stdio.h>
/* extern int fprintf(); CHANGE 9/3 */
/* Global types */
/* Possible settings for the Diagnostic Reporting Level */
enum Diagnostic_Level { NONE, ERROR, INFORM, DEBUG };
/* Declaration of global variables */
extern enum Diagnostic_Level current_level;
extern FILE *error_fp;
/* macros for doing Diagnostic Report */
#define ERROR_MSG( s )\
do{ if ( current_level >= ERROR ) fprintf( error_fp, "(e) %s\n", s); }while(0)
#define INFORM_MSG( s )\
do{ if ( current_level >= INFORM ) fprintf( error_fp, "(i) %s\n", s); }while(0)
#define DEBUG_MSG( s )\
do{ if ( current_level >= DEBUG ) fprintf( error_fp, "(d) %s\n", s); }while(0)
/* buffer control */
#define BUFFER_BLOCK 32
extern void Buffer_MSG( enum Diagnostic_Level, char *);
extern void Flush_MSG( void );
#endif
这是来自编译器的(相关)消息:
GNU C (GCC) version 4.5.3 (i686-pc-cygwin)
compiled by GNU C version 4.5.3, GMP version 4.3.2, MPFR version 3.0.1-p4, MPC version 0.8
warning: MPFR header version 3.0.1-p4 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129520
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/include"
ignoring duplicate directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include-fixed
/usr/include
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api
End of search list.
GNU C (GCC) version 4.5.3 (i686-pc-cygwin)
compiled by GNU C version 4.5.3, GMP version 4.3.2, MPFR version 3.0.1-p4, MPC version 0.8
warning: MPFR header version 3.0.1-p4 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129520
Compiler executable checksum: 89d6774c1d510265da7d48b735ce61fb
diagmesg.c:17:1: error: initializer element is not constant
Makefile:101: recipe for target `diagmesg.o' failed
make: *** [diagmesg.o] Error 1
源代码中的第 17 行是 FILE * error_fp = stderr;
上面显示的语句
我不是一个常规的 C 程序员。如果有人能澄清“初始化元素不是常量”的含义和/或可能的编译解决方案将非常感激。