Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

C++ comments in Mex files under Linux

Asked by Jan Simon on 6 Jun 2011

For many years users support problems about compiling C-sources containing C++ comments under Linux, because the automatically created mexopts file enables the -ansi style instead of the modern std=-c99 style for the GCC compiler.

Other compilers accept the C++ comments for a long time: LCC (shipped with Matlab or downloaded from the net), Borland BCC, OpenWatcom, MSVC, Intel ICC, Tiny C (TCC), PCC, ...

Is there any reason not to enable the 12 year old C99 standard in the default mexopts file for the GCC under Linux?

 

BTW: To solve the problem, you can edit the mexopts file: replace '-ansi' by '-std=c99' or add these flags to the MEX call:

mex -O CFLAGS="\$CFLAGS -std=c99" yourfile.c

1 Comment

Matt on 3 Apr 2013

I have a follow-up question... I am using Simulink s-functions that have C++ style comments. I have changed the CFLAGS option in the mexopts file and can mex the S-functions no problem. However, when I run the model in rapid accelerator mode, it appears to recompile the s-functions and uses -ansi instead of -std=c99.

Is there a recommended way to address this problem? I have found a solution, but it involves manually changing the MODEL.mk file in the slprj folder or actually changing the default raccel tmf file, both of which seem sketchy to me.

EDIT: More info... I traced it back to unixtools.mk, which changes the CFLAGS based on the value of TGT_FCN_LIB in the makefile. Apparently, TGT_FCN_LIB takes the value of ANSI_C, ISO_C, or GNU and the CFLAGS change accordingly. TGT_FCN_LIB is set in the MODEL.mk makefile, but I am not sure what parameter in the model's configuration parameters determines its value (if any). I manually changed it to ISO_C in MODEL.mk and everything compiles fine.

EDIT 2: I have reposted this as a new question ( http://www.mathworks.com/matlabcentral/answers/69768-c-style-comments-in-s-functions-with-linux)

Jan Simon

Products

No products are associated with this question.

1 Answer

Answer by James Tursa on 6 Jun 2011
Accepted answer

Probably it's the same reason they still include the silly "/fixed" option on the Fortran mexopts.bat files (which forces free-format source code to be interpreted by the compiler as fixed-format source code). It doesn't affect their sample code and they haven't had enough user complaints to motivate them to change it (which would require them to re-validate all of their sample code I presume).

2 Comments

James Tursa on 6 Jun 2011

BTW, first thing I do after installing a new MATLAB version is to go change the mexopts.bat files to remove the "/fixed" option from the COMPFLAGS line.

Jan Simon on 6 Jun 2011

Then I have to forward all complaints from Linux users concerning the C99 comments in my numerous C-Mex FEX submissions to the TMW staff.

James Tursa

Contact us