MATLAB Compiler | ![]() ![]() |
Controlling Comments in Output Code
Use the annotation:type
option to include your initial M-file comments and code in your generated C or C++ output. The possible values for type
are
Not specifying any annotation type uses the default of all
, which includes the complete source of the M-file (comments and code) interleaved with the generated C/C++ source.
The following sections show segments of the generated code from this simple Hello, World example:
Note
To improve the readability of your generated code, turn off optimizations with -O none or -g . The examples in this section have optimizations off.
|
Comments Annotation
To include only comments from the source M-file in the generated output, use
This code snippet shows the generated code containing only the comments ("This is the hello ...
") in the middle of the routine:
static void Mhello(void) { mclMlineEnterFunction("D:\\work\\hello.m", "hello") mexLocalFunctionTable save_local_function_table_ = mclSetCurrentLocalFunctionTable(&_local_function_table_hello); mxArray * ans = NULL; /* * This is the hello, world function written in M code */ mclMline(3); mclAssignAns( &ans, mlfNFprintf(0, mlfScalar(1), mxCreateString("Hello, World\\n"), NULL)); mxDestroyArray(ans); mclSetCurrentLocalFunctionTable(save_local_function_table_); mclMlineExitFunction(); }
All Annotation
To include both comments and source code from the source M-file in the generated output, use
or do not stipulate the annotation option, thus using the default of all
.
This code snippet contains both comments and source code:
static void Mhello(void) { mclMlineEnterFunction("D:\\work\\hello.m", "hello") mexLocalFunctionTable save_local_function_table_ = mclSetCurrentLocalFunctionTable(&_local_function_table_hello); mxArray * ans = NULL; /* * % This is the hello, world function written in M code * fprintf(1,'Hello, World\n' ); */ mclMline(3); mclAssignAns( &ans, mlfNFprintf(0, mlfScalar(1), mxCreateString("Hello, World\\n"), NULL)); mxDestroyArray(ans); mclSetCurrentLocalFunctionTable(save_local_function_table_); mclMlineExitFunction(); }
No Annotation
To include no source from the initial M-file in the generated output, use
This code snippet shows the generated code without comments and source code:
static void Mhello(void) { mclMlineEnterFunction("D:\\work\\hello.m", "hello") mexLocalFunctionTable save_local_function_table_ = mclSetCurrentLocalFunctionTable(&_local_function_table_hello); mxArray * ans = NULL; mclMline(3); mclAssignAns( &ans, mlfNFprintf(0, mlfScalar(1), mxCreateString("Hello, World\\n"), NULL)); mxDestroyArray(ans); mclSetCurrentLocalFunctionTable(save_local_function_table_); mclMlineExitFunction(); }
![]() | Including M-File Information in Compiler Output | Controlling #line Directives in Output Code | ![]() |