为什么语法正确时VS2010会给出语法错误? [英] Why does VS2010 give syntax errors when syntax is correct?

查看:37
本文介绍了为什么语法正确时VS2010会给出语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 VS2010(和 VS2008)时遇到了问题,给了我一个很好的语法错误列表.但是,语法确实是正确的.这是一个小例子;

我在 .h 文件中有以下代码块

//原型声明LIST* createList (int (*compare) (void*, void*));LIST* destroyList (LIST* plist);int addNode (LIST* pList, void* dataInPtr);bool removeNode (LIST* pList, void* keyPtr, void** dataOutPtr);bool searchList (LIST* pList, void* pArgu, void** pDataOut);bool retrieveNode (LIST* pList, void* pArgu, void** dataOutPtr);bool traverse (LIST* pList, int fromWhere, void** dataOutPtr);int listCount (LIST* pList);bool isListEmpty (LIST* pList);bool isListFull (LIST* pList);

LIST 是一个 typedef 的结构,仅供参考.所有这些函数声明似乎都是正确的语法.然而,在尝试构建时,我从第一个 bool 函数开始出现以下语法错误,顺着列表向下.

<块引用>

错误 2 错误 C2059:语法错误:';'

我看不出问题出在哪里.同样,这只是一个小例子.我还收到如下语法错误

bool 找到;

<块引用>

错误 29 错误 C2065: 'bool' : 未声明的标识符

我真的迷失了这个.这里发布的代码不是我自己的,它来自一本数据结构书,但看起来还是正确的.任何帮助,将不胜感激.谢谢!

解决方案

bool 不是 C 中的基本类型.

Visual C++ 只实现了 C90,它没有 bool 类型.C99 通过 <stdbool.h> 标头添加了对 bool 的支持,但 Visual C++ 不支持.

您应该使用 int 或为 bool 创建自己的 typedef.

I am having a problem with VS2010 (and VS2008) giving my a great list of syntax errors. However, the syntax is indeed correct. Here is a small example;

I have the following code block inside a .h file

// Prototype Declarations
LIST*   createList     (int (*compare) (void*, void*));
LIST*   destroyList    (LIST* plist);
int     addNode      (LIST* pList, void* dataInPtr);
bool    removeNode      (LIST* pList, void* keyPtr, void** dataOutPtr);
bool    searchList      (LIST* pList, void* pArgu, void** pDataOut);
bool    retrieveNode    (LIST* pList, void* pArgu, void** dataOutPtr);
bool    traverse        (LIST* pList, int fromWhere, void** dataOutPtr);
int     listCount    (LIST* pList);
bool    isListEmpty     (LIST* pList);
bool    isListFull      (LIST* pList);

LIST is a typedef'd struct, FYI. All of these function declarations appear to be correct syntax. Yet, when attempting to build, I get the following syntax errors starting at the first bool function, going down the list.

Error 2 error C2059: syntax error : ';'

I'm failing to see where the problem lies. Again, this is just a small example. I also receive syntax errors such as the following

bool found;

Error 29 error C2065: 'bool' : undeclared identifier

I'm truly at a lost on this one. The code posted here isn't my own, it's from a data structures book, but again it looks correct. Any help would be appreciated. Thanks!

解决方案

bool is not a fundamental type in C.

Visual C++ only implements C90, which has no bool type. C99 added support for bool via the <stdbool.h> header, but Visual C++ does not support this.

You should either use int or create your own typedef for bool.

这篇关于为什么语法正确时VS2010会给出语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆