2010-09-11 95 views
2

我想用C语言编写一个函数,但是可以从C++中调用,它需要一个受限制的指针。这仅在c99中可用,所以g ++不喜欢它,即使在extern "C"块中。我怎样才能解决这个限制?在C++的`extern“C”块中使用c99

+3

'extern“C”并不意味着包含的代码是C,这意味着在那里声明的任何函数或项都将使用C链接。 – 2010-09-11 01:09:44

+0

只是在开玩笑:尝试'extern“C99”' – pmg 2010-09-11 12:08:45

+0

类似的问题在这里:struct XY a = {.x = 1,.y = 2};'不会在extern“C”块内编译:_error:expected primary- '。'token_之前的表达,令人沮丧!相反,过时的形式'struct XY a = {x:1,y:2};'工作。哎哟! – gatopeich 2011-04-15 16:42:42

回答

1
#ifdef __cplusplus 
# ifdef __GNUC__ 
#  define restrict __restrict__ // G++ has restrict 
# else 
#  define restrict // C++ in general doesn't 
# endif 
#endif