83210

What does the %#mex pragma do?

When I create a MEX file in MATLAB, I'm in the habit of also creating a .m file with the same name, a function signature identical to the MEX file, and otherwise containing nothing but help text in the form of comments, that are then displayed when one types help myfcn.

When one does this, a small side-effect is that MATLAB Code Analyzer picks up on the fact that the input and output arguments specified in the function signature are unused, and flags them with an orange underline.

Recently I've discovered that several MathWorks internal functions follow something similar to this pattern, but also including the following line, separated by a blank line from the main help text:

%#mex

This %#mex pragma appears to be undocumented (at least I can't find any reference to it). It would appear to be used to directly indicate that a .m file is intended only to provide help text for a MEX file. It has the effect of suppressing any Code Analyzer messages in the file.

Is anyone familiar with the intended use of the %#mex pragma? Does it have any other effects other suppressing Code Analyzer messages?

Examples:

\toolbox\compiler\mcc.m \toolbox\images\images\private\ddist.m \toolbox\matlab\audiovideo\private\readavi.m \toolbox\matlab\imagesci\hdf.m \toolbox\matlab\sparfun\arpackc.m \toolbox\matlab\specgraph\private\ditherc.m

Answer1:

Apparently this was documented in older releases. Here is a page from the archived documentation going all the way back to version 3.0 of the MATLAB Compiler (circa MATLAB 6.5 R13):

%#mex

This pragma informs the MATLAB Compiler to select the MEX-file over an existing M-file.

If you are using the %#function pragma to define functions that are not available in M-code, you should use the %#external pragma to define the function. For example:

function y = gamma(x) %#mex error('gamma MEX-file is missing');

Here is another related page that explains when this pragma is used:

It is now possible to call MEX-files from Compiler-generated stand-alone applications. The Compiler will compile MEX-files whenever they are specified on the command line or are located using the -h option to find helper functions. The MEX-files will then be loaded and called by the stand-alone code.

If an M-file and a MEX-file appear in the same directory and the M-file contains at least one function, the Compiler will compile the M-file instead of the MEX-file. If the MEX-file is desired instead, you must use the %#mex pragma. For more information on this pragma, see the %#mex reference page.

of course the MATLAB Compiler was a completely different product back then, capable of producing standalone C/C++ programs and MEX-files (no MCR dependency like today's version)

It seems that mlint still recognizes this pragma and completely excludes the M-file from analysis.

Recommend

  • Read 4D Array in MEX File
  • How to add header files path relative to the current file?
  • Modifying resource contents of a running executable
  • Matlab Codegen Eig Function - Is this a Bug?
  • Save pictures to custom folder in media library
  • Using Matlab “engine.h” from c++ correctly
  • MSVC 2015 /Wall has lots of not useful messages
  • XMPP push notifications causing problems (delay + duplications) in messages
  • Interpret strings as packed binary data in C++
  • Refreshing i18n translated string interpolated values in Aurelia
  • C++: Use input string as variable name
  • Return null in boolean to checkbox state converter in XAML
  • Why does the following throw an “Object doesn't support property or method 'importNode
  • Is there any purpose for h2-h6 headings in HTML5?
  • Prolog Ambiguous Output
  • Microsoft Excel Pivot miscalculation in Sum for positive and negative numbers
  • C++ Single function pointer for all template instances
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • Why must we declare a variable name when adding a method to a struct in Golang?
  • How to autopopulate a field in SugarCRM form
  • Using Sax parsing to edit and write XML in VB6
  • Checking if an array in C is symmetric
  • C++ pointer value changes with static_cast
  • Differences in dis-assembled C code of GCC and Borland?
  • How integrated is Collada to OpenGL ES
  • Rails Find when some params will be blank
  • debug library loaded with ctypes using gdb
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Test if a set exists before trying to drop it
  • Django: Count of Group Elements
  • Get one-time binding to work for ng-if
  • Is there any way to access browser form field suggestions from JavaScript?
  • output of program is not same as passed argument
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Statically linking a C++ library to a C# process using CLI or any other way
  • Why winpcap requires both .lib and .dll to run?
  • Akka Routing: Reply's send to router ends up as dead letters
  • Traverse Array and Display in markup
  • unknown Exception android
  • Checking variable from a different class in C#