繁体   English   中英

C - 奇怪的语法错误

[英]C - weird syntax error

我在ANSI C(Visual Studio 2010)中编写应用程序,我的库看起来像这样:

#include <stdio.h>
#include <stdlib.h>

#ifndef _MYLIB_
#define _MYLIB_

typedef enum {false, true} bool;

// some structures and function prototypes...

#endif

我在每个.c文件中都包含了这个库(我有4个.c文件 - 1个带有main()的main.c和带有函数的其余部分)。

我收到一个错误:

Generating Code...
1>  first.cpp
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : 'constant'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2143: syntax error : missing ';' before '}'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : '}'
1>  second.cpp
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : 'constant'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2143: syntax error : missing ';' before '}'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : '}'

更重要的是 - 当我将所有函数和结构粘贴到main.c中时 - 它正常工作......我不知道如何解决它...

我坚信你在干扰C ++内置的falsetrue ,所以你试图在你的enum重新定义它们。

尝试用FALSETRUE替换falsetrue ,用BOOL替换bool

#include <stdio.h>
#include <stdlib.h>

#ifndef _MYLIB_
#define _MYLIB_

typedef enum {FALSE, TRUE} BOOL;

// some structures and function prototypes...

#endif

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM