It is challenging to port from Linux to OS/X. I have an inline function embedded inside another function body. On Linux, gcc happily compiled the code, but on OS/X, clang reports error.
Here is the code snippet,
$ cat inline.c void func() { inline int max(int a, int b) { return (a>b) ? a : b; } int c = max(11,22); } On Linux, everything is fine,
Linux $ gcc -c inline.c Linux $$ gcc --version gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010 However, clang on OS/X complains,
OSX $ cc -c inline.c inline.c:2:38: error: function definition is not allowed here inline int max(int a, int b) { return (a>b) ? a : b; } ^ inline.c:3:17: warning: implicit declaration of function 'max' is invalid in C99 [-Wimplicit-function-declaration] int c = max(11,22); ^ 1 warning and 1 error generated. OSX $ cc --version Apple LLVM version 7.3.0 (clang-703.0.31) Target: x86_64-apple-darwin15.5.0 Is this a gcc "feature" or there is a clang flag to enable this capability?
maxin that function in the real code?inlinehere makes no sense at all. It is a precious tool if you want to place function definitions in header files such they are visible in several .c files. Everything that is found inside the same .c file can be inlined by the compiler without notice, here it is simply superfluous.