math.h编译错误:期望的声明说明符或'...'之前'('

math.h编译错误:期望的声明说明符或'...'之前'('

问题描述:

我想编译一个相当大的项目。几个文件包括math.h。我得到的编译错误是:math.h编译错误:期望的声明说明符或'...'之前'('

"In file included from math.h:71:0, 

mathcalls.h:310:1: error: expected declaration specifiers or '...' before '(' token" 

我知道我的数学头没有被改变,他们包括了“你好数学世界”节目,我只写了罚款,所以我不知道是什么问题。在mathcalls具体的线路。这是给错误.h文件是

/* Round X to nearest integral value, rounding halfway cases away from 
    zero. */ 
__MATHCALLX (round,, (_Mdouble_ __x), (__const__)); 

任何线索的问题是什么吗?

+2

才能确保所有的标题被适当的ifdef只包含一次? – Bort 2012-02-29 17:10:29

+0

您确定包含在文件范围内吗? – wildplasser 2012-02-29 17:51:15

+0

我从特定文件中删除了#include ,现在正在编译。其他文件中包含。我仍然不明白问题是什么。 Math.h有自己的#ifndef来防止它被多次包含。至少现在正在编译。 – 2012-02-29 17:55:21

您在包含<math.h>之前定义了round。事情是这样的:

#define round(x) trunc((x+0.5)) 
#include <math.h> 

编译上面的代码用gcc-4.6.2打印以下错误:

In file included from /usr/include/math.h:71:0, 
       from a.c:2: 
/usr/include/bits/mathcalls.h:310:1: error: expected declaration specifiers or '...' before '(' token 
+0

如果您先定义'log2',或首先在mathcalls.h中使用一堆其他事物,则会发生相同类型的错误。这只发生在gcc上,而不是其他编译器(如Visual Studio)。 – 2012-12-14 00:07:48