How can I prevent MATLAB Coder from truncating the variable names in generated code?

I am using MATLAB Coder to convert MATLAB Code to C Code. In the generated code, MATLAB Coder truncates the names of any global variables that are longer than 30 characters. Additionally, MATLAB adds identifiers like "c_*", or "d_"*" to the start of variables to distinguish ones that become the same after truncation. As a result, I am no longer able to differentiate between the variables without searching through the code. For example, suppose I have the following variables in my MATLAB code:
global this_is_a_very_long_variable_name
global this_is_a_very_long_variable_name_to_use 
After MATLAB Coder conversion, these variables have the following names in the generated C code
c_this_is_a_very_long_variable_ 
d_this_is_a_very_long_variable_
Is there a way to avoid truncating the variable names in MATLAB Coder? 

 Accepted Answer

You can avoid truncating the variable names by specifying the maximum identifier length.
To specify the maximum length in MATLAB Coder app:
  1. Proceed to the 'Generate Code' pane and click on the 'More Settings' option. This will open a pop-up where several options are visible.
  2. Now, navigate to 'Code Appearance' tab on the left side tab. You will see the 'Maximum Identifier length' field set to a default of 31. You can specify maximum number of characters in generated function, type definition, and variable names here. To avoid truncation of identifiers by the target C compiler, specify a value that matches the maximum identifier length of the target C compiler.
Please note that this parameter does not apply to exported identifiers, such as the generated names for entry-point functions or emxArray API functions. If the length of an exported identifier exceeds the maximum identifier length of the target C compiler, the target C compiler truncates the exported identifier.

More Answers (0)

Products

Release

R2015b

Community Treasure Hunt

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

Start Hunting!