I am developing an embedded C application in a C90-compliant compiler which, on the other hand, for testing and debugging purposes, is deployed in Matlab/Simulink interfacing the application with a CPP file. This bundle is compiled instead with Matlab MEX, which is configured to use Visual Studio 2005 to build.
This means we have one CPP file, and a couple of .C/.H files that are built altogether. This workflow has been successful for me, using the #ifdef __cplusplus extern "C" {...}
trick on each C call.
However, I have come with a problem when the need of inline functions arose due to time constraints in the embedded application.
Next, SSCCE built in VS2005:
main.cpp
#include "c_method.h"
void main()
{
for(int b = 0; b < 9; b++)
int a = c_method(b);
}
c_method.c
#include "c_method.h"
inline int inline_fun(int x)
{
return x+1;
}
int c_method(int b)
{
return inline_fun(b);
}
c_method.h
#ifndef __C_METHOD_H__
#define __C_METHOD_H__
int c_method(int b);
#endif
Which provides the following errors:
c_method.c(7) : error C2054: expected '(' to follow 'inline'
c_method.c(8) : error C2085: 'inline_fun' : not in formal parameter list
c_method.c(8) : error C2143: syntax error : missing ';' before '{'
I noticed I missed extern "C" {...}
but did not work either.
As read here in SO, changing c_method.c
to c_method.cpp
will do the trick, however I'd rather have an alternative solution, if exists any, as I'm not very confident about the embedded C compiler accepting the cpp extension without coming whining to me...
Thank you.
Added
@πάντα ῥεῖ got with the answer. Creating an empty declaration of inline will do the trick.
However, as @Lundin suggests, I'll meditate the possibility of using another C compiler for the PC platform build.