Unable to use inline in declaration get error C2054

Question:

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 '{'

Solution:

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

猜你喜欢

转载自blog.csdn.net/domine123/article/details/86491399