C语法 - 错误C2143:语法错误:在'*'之前缺少')'
为什么我的C头声明中出现语法错误?C语法 - 错误C2143:语法错误:在'*'之前缺少')'
这里是我的头文件,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
据我所见/可以告诉,这是C声明的有效语法。如果我将viterbi.c编译为C++代码(viterbi.cpp),那么错误消失。什么是语法错误?
bool
不是本地C类型,但对于那些使用C99的尝试,请尝试添加行#include <stdbool.h>
,其中包含一个定义bool
的宏。
由于所有Visual Studio/MSVC产品中的C编译器都使用C89,因此根本没有为您定义bool
作为本机C类型或其他类型。解决方法包括使用typedef
或enum
来定义bool
。示例位于下面的链接中。
欲了解更多信息,请参见:Is bool a native C type?
宏'bool'不是原生的,但它通过一个宏映射到该头部的本机类型_Bool(强制性的),这是因为在野外编写的C代码太多,它定义了它们自己的'bool'版本(你可能会感到惊讶, ppl是如何定义他们自己的布尔类型)所以你可以使用_Bool作为本机类型(我不推荐它) – Olaf
@Keith我的VS 2010编译器支持C89/90,所以我必须寻找anot她的解决方案 –
@StephenWang这就是我的意思,你需要宏Olaf的标题解释为可见。你试过了吗?在没有include的情况下,在ideone.com上编译失败并成功。 –
有没有这样的事情在''C' bool'(89)。你想用Visual Studio编译'C'代码,那么你必须编写'C'代码,而不是'C++'代码。 – PaulMcKenzie
看起来像'bool'可能是问题所在:http://stackoverflow.com/a/18042253 – jonhopkins
@PaulMcKenzie:'bool'是一个映射到**标准类型**'_Bool'的宏。并且有建议不要在应用程序中重新定义'bool'等。而C不是C89,而是标准C,它只是** C11。 – Olaf