MATLAB Compiler | ![]() ![]() |
Controlling #line Directives in Output Code
#line
preprocessing directives inform a C/C++ compiler that the C/C++ code was generated by another tool (MATLAB Compiler) and they identify the correspondence between the generated code and the original source code (M-file). You can use the #line
directives to help debug your M-file(s). Most C language debuggers can display your M-file source code. These debuggers allow you to set breakpoints, single step, and so on at the M-file code level when you use the #line
directives.
Use the line:
setting
option to include #line
preprocessor directives in your generated C or C++ output. The possible values for setting
are
Not specifying any line
setting uses the default of off
, which does not include any #line
preprocessor directives in the generated C/C++ source.
Note
When using the #line directive, the page-width directive is disabled in order to make the code work properly with the C debugger.
|
Include #line Directives
To include #line
directives in your generated C or C++ code, use
The Hello, World example produces the following code segment when this option is selected. (Note that several lines have been truncated for readability.)
#line 1 "D:\\work\\hello.m" /* Line 1 */ static void Mhello(void) { #line 1 "D:\\work\\hello.m" /* Line 1 */ mclMlineEnterFunction("D:\\work\\hello.m", "hello") #line 1 "D:\\work\\hello.m" /* Line 1 */ mexLocalFunctionTable save_local_function_table_ = --> #line 1 "D:\\work\\hello.m" /* Line 1 */ mxArray * ans = NULL; /* * % This is the hello, world function written in M code * fprintf(1,'Hello, World\n' ); */ #line 3 "D:\\work\\hello.m" /* Line 3 */ mclMline(3); #line 3 "D:\\work\\hello.m" /* Line 3 */ mclAssignAns(&ans, mlfNFprintf(0, mlfScalar(1), mxCreateString("Hello,--> #line 3 "D:\\work\\hello.m" /* Line 3 */ mxDestroyArray(ans); #line 3 "D:\\work\\hello.m" /* Line 3 */ mclSetCurrentLocalFunctionTable(save_local_function_table_); #line 3 "D:\\work\\hello.m" /* Line 3 */ mclMlineExitFunction(); #line 3 "D:\\work\\hello.m" /* Line 3 */ }
In this example, Line 1 points to lines in the generated C code that were produced by line 1 from the M-file, that is
Line 3 points to lines in the C code that were produced by line 3 of the M-file, or
![]() | Controlling Comments in Output Code | Controlling Information in Run-Time Errors | ![]() |