From: Jan Simon on
Dear Oliver!

> > As far as I understood "-ansi" is documented to be "-std=c89", so this *must* conflict with "-std=c99". This means, that the "-ansi" should be removed from the mexopts if the user does not want to restrict the C-code to a 20 year old standard.
>
> I agree there is a conflict. The question is how is this conflict resolved.

If the mexopts file defines a crucial flag, which let the compiler fail for modern coding style, the mexopts file is corrupted. So it is a job for TWM to remove the -ansi flag.

The longer I gaze to the problem, the more ridiculous it looks: The comment style let the compiler fail, although the comments are ignored at all by definition!

I've inspected the function mex.m to find out, in which order the flags are forwarded to the compiler. To my surprise, the M-function mex calls a Perl function, which parses (not calls!) a BAT file (on a Win-PC) "mexopts.bat", which was created by another Perl function.
This is pure obfuscation. It must be possible to simplify this drastically and make it much easier for users to toggle an -ansi or -std=c99 flag!

Deeply impressed, Jan
From: Oliver Woodford on
"Jan Simon" wrote:
> Google found this, but I cannot try it (no Liniux currently):
> mex -O CFLAGS="\$CFLAGS -Wp,-lang-c-c++-comments" Shuffle.c

I can confirm this doesn't work for me (MATLAB R2009b, Ubuntu 9.10 64-bit, gcc 4.4).

> The longer I gaze to the problem, the more ridiculous it looks: The comment style let the compiler fail, although the comments are ignored at all by definition!
>
> I've inspected the function mex.m to find out, in which order the flags are forwarded to the compiler. To my surprise, the M-function mex calls a Perl function, which parses (not calls!) a BAT file (on a Win-PC) "mexopts.bat", which was created by another Perl function.
> This is pure obfuscation. It must be possible to simplify this drastically and make it much easier for users to toggle an -ansi or -std=c99 flag!

It's far from optimal, and could definitely be improved.

Oliver