Borrar filtros
Borrar filtros

Using c++ style comments in mex files.

5 visualizaciones (últimos 30 días)
Pei JIA
Pei JIA el 22 de En. de 2011
I'm testing simple mex functions today and I would like to add some comments. However, I noticed:
  1. If my comments are surrounded by "/* \*/", namely, /*comments*/, the compilation of mex file works fine.
  2. But if my comments are commented in the way using "//", namely, //comments, the compilation fails.
Can anybody help to explain why it is so? Does that mean, I'm not able to write comments in the way of "//comments" in Matlab mex files?

Respuesta aceptada

Jan
Jan el 26 de En. de 2011
While the LCC compiler shipped with Matlab, modern LCC versions, Borland BCC, OpenWatcom, MSVC und Intel compilers understand the C99 comment style, the GCC compiler needs to enable them explicitely on Linux:
mex('CFLAGS="\$CFLAGS -std=c99"', 'File.c')

Más respuestas (1)

Walter Roberson
Walter Roberson el 22 de En. de 2011
Were you using C or C++ ? C++ has always accepted // comments, but the original 1989 C standard did not accept them. If you are using the default LCC compiler then possibly it does not accept them. You may have to specifically configure your compiler to use the C99 standard if you are using C.
  5 comentarios
Jan
Jan el 29 de En. de 2011
@James: As far as I know, only GCC without -std=c99 fails to interprete this 12 year old standard. And I do not understand, why MathWorks does not include this flag as standard in the mexopts file.
Do you know other compiler, which insiste on c89 style?
James Tursa
James Tursa el 29 de En. de 2011
No. I haven't researched this. I just got tired of all the problems that gcc users had with compiling my FEX submissions. Actually, I still write with the // style, I just use a simple conversion program after the fact to produce the files I submit.

Iniciar sesión para comentar.

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by