Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

c - Why does VS2010 give syntax errors when syntax is correct?

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...