Reputation: 283
I'm trying to compile some open source projects using the vs2013 c/c++ compiler. The file is .c extension. The below code returns some errors (below). All of which can be "fixed" by simply removing the inline in the declaration. Note: not a real function, just illustrative
static inline int pthread_fetch_and_add(int *val, int add, int *mutex)
{
return 0;
}
errors error C2054: expected '(' to follow 'inline' error C2085: 'pthread_fetch_and_add' : not in formal parameter list error C2143: syntax error : missing ';' before '{'
Upvotes: 22
Views: 17552
Reputation: 145829
Use __inline
with MSVC.
inline
is a c99 keyword and c99 is not yet (fully) supported with MSVC.
"The inline keyword is available only in C++. The __inline and __forceinline keywords are available in both C and C++. For compatibility with previous versions, _inline is a synonym for __inline."
Source: http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
#if !defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER < 1900
# define inline __inline
#endif
Note that
1900
means Visual-studio-2015, I mean, said version supports inline in .c files (so c99 standard is little more supported, but not fully).
Upvotes: 38
Reputation: 125854
I ran into the same issue. Instead of changing every inline
to __inline
, I added the following before all of the function declarations:
#if defined(_MSC_VER)
#define inline __inline
#endif
This would allow the original code to still be compiled as-is with a different compiler (that presumably didn't have the same limitations as the VS one).
Upvotes: 2
Reputation: 168
A simple workaround is to -Dinline=__inline with the MSVC compiler.
Upvotes: 8