C syntax - error C2143: syntax error : missing ')' before '*'
C syntax - error C2143: syntax error : missing ')' before '*'
为什么我的 C header 声明出现语法错误?
这是我的 header 文件,viterbi.h:
#ifndef VITERBI_H
#define VITERBI_H
void vitdec(float* , int , int , bool* );
#endif //VITERBI_H
这是我的实现文件,viterbi.c:
// viterbi.c : Defines the entry point for the console application.
//
#include "viterbi.h"
#include "math.h"
//void vitdec(float* sd, int frameLen, int rate, bool* hd);
void vitdec(float* sd, int frameLen, int rate, bool* hd)
{
//... The rest of the function
Visual Studio 2010 编译器的错误为:
viterbi.h(4): error C2143: syntax error : missing ')' before '*'
viterbi.h(4): error C2081: 'bool' : name in formal parameter list illegal
viterbi.h(4): error C2143: syntax error : missing '{' before '*'
viterbi.h(4): error C2059: syntax error : ')'
viterbi.h(4): error C2059: syntax error : ';'
viterbi.c(7): error C2065: 'bool' : undeclared identifier
viterbi.c(7): error C2065: 'hd' : undeclared identifier
viterbi.c(7): warning C4552: '*' : operator has no effect; expected operator with side-effect
据我所知 seen/can,这是 C 声明的有效语法。如果我将 viterbi.c 编译为 C++ 代码 (viterbi.cpp),那么错误就会消失。什么是语法错误?
bool
不是本机 C 类型,但对于使用 C99 的用户,请尝试添加行 #include <stdbool.h>
,其中包含定义 bool
.
的宏
由于所有 Visual Studio/MSVC 产品中的 C 编译器都使用 C89,因此 bool
根本没有为您定义为本机 C 类型或其他类型。解决方法包括使用 typedef
或 enum
来定义 bool
。示例如下 link.
有关详细信息,请参阅:Is bool a native C type?
为什么我的 C header 声明出现语法错误?
这是我的 header 文件,viterbi.h:
#ifndef VITERBI_H
#define VITERBI_H
void vitdec(float* , int , int , bool* );
#endif //VITERBI_H
这是我的实现文件,viterbi.c:
// viterbi.c : Defines the entry point for the console application.
//
#include "viterbi.h"
#include "math.h"
//void vitdec(float* sd, int frameLen, int rate, bool* hd);
void vitdec(float* sd, int frameLen, int rate, bool* hd)
{
//... The rest of the function
Visual Studio 2010 编译器的错误为:
viterbi.h(4): error C2143: syntax error : missing ')' before '*'
viterbi.h(4): error C2081: 'bool' : name in formal parameter list illegal
viterbi.h(4): error C2143: syntax error : missing '{' before '*'
viterbi.h(4): error C2059: syntax error : ')'
viterbi.h(4): error C2059: syntax error : ';'
viterbi.c(7): error C2065: 'bool' : undeclared identifier
viterbi.c(7): error C2065: 'hd' : undeclared identifier
viterbi.c(7): warning C4552: '*' : operator has no effect; expected operator with side-effect
据我所知 seen/can,这是 C 声明的有效语法。如果我将 viterbi.c 编译为 C++ 代码 (viterbi.cpp),那么错误就会消失。什么是语法错误?
bool
不是本机 C 类型,但对于使用 C99 的用户,请尝试添加行 #include <stdbool.h>
,其中包含定义 bool
.
由于所有 Visual Studio/MSVC 产品中的 C 编译器都使用 C89,因此 bool
根本没有为您定义为本机 C 类型或其他类型。解决方法包括使用 typedef
或 enum
来定义 bool
。示例如下 link.
有关详细信息,请参阅:Is bool a native C type?