Reserved Keywords
The code generator reserves the use of certain identifiers in the generated code. These identifiers include C and C++ keywords and C and C++ standard library names. Using these keywords in your MATLAB® code as identifiers or function names might cause the code generator to rename them. If you do not find variables or functions that have reserved keywords as names in your generated code, they might have been renamed by the code generator.
Note
You can preserve most variable names, apart from the reserved keywords, in your generated code. See Preserve Variable Names in Generated Code.
C Reserved Keywords
_Bool | _Complex | _Generic | _Imaginary |
_Noreturn | _Static_assert | _Thread_local | threads |
asm | auto | assert | case |
char | const | continue | default |
complex | void | time | tgmath |
ctype | iso646 | stdatomic | stddef |
do | double | else | enum |
extern | float | for | goto |
if | inline | int | long |
limits | locale | stdbool | stdio |
register | restrict | return | short |
signal | wctype | setjmp | string |
signed | sizeof | static | struct |
single | _Alignas | _Alignof | _Atomic |
stdalign | inttypes | stdarg | uchar |
stdint | math | errno | wchar |
stdlib | stdnoreturn | break | fenv |
switch | typedef | typeof | union |
true | false | bool | fortran |
unsigned | while | volatile |
C++ Reserved Keywords
algorithm | cstddef | iostream | sstream |
any | cstdint | istream | stack |
array | cstdio | iterator | static_cast |
atomic | cstdlib | limits | stdexcept |
bitset | cstring | list | streambuf |
cassert | ctgmath | locale | string_view |
catch | ctime | map | strstream |
ccomplex | cuchar | memory | system_error |
cctype | cwchar | memory_resource | template |
cerrno | cwctype | mutable | this |
cfenv | delete | mutex | thread |
cfloat | deque | namespace | throw |
chrono | dynamic_cast | new | try |
cinttypes | exception | numeric | tuple |
ciso646 | execution | operator | typeid |
class | explicit | optional | type_traits |
climits | export | ostream | typeindex |
clocale | filesystem | private | typeinfo |
cmath | foreward_list | protected | typename |
codecvt | friend | public | unordered_map |
complex | fstream | queue | unordered_set |
condition_variable | functional | random | using |
const_cast | future | ratio | utility |
csetjmp | initializer_list | regex | valarray |
csignal | inline | reinterpret_cast | vector |
cstdalign | iomanip | scoped_allocator | virtual |
cstdarg | ios | set | wchar_t |
cstdbool | iosfwd | shared_mutex |
Keywords Reserved for Code Generation
abs | fortran | localZCE | rtNaN |
asm | HAVESTDIO | localZCSV | SeedFileBuffer |
bool | id_t | matrix | SeedFileBufferLen |
boolean_T | int_T | MODEL | single |
byte_T |
int8_T | MT | TID01EQ
|
char_T | int16_T | NCSTATES | time_T |
cint8_T | int32_T | NULL | true |
cint16_T | int64_T | NUMST | TRUE |
cint32_T | INTEGER_CODE | pointer_T | uint_T |
creal_T | LINK_DATA_BUFFER_SIZE | PROFILING_ENABLED
| uint8_T |
creal32_T | LINK_DATA_STREAM | PROFILING_NUM_SAMPLES | uint16_T |
creal64_T | localB | real_T | uint32_T |
cuint8_T | localC | real32_T | uint64_T |
cuint16_T | localDWork | real64_T | UNUSED_PARAMETER |
cuint32_T | localP | RT | USE_RTMODEL
|
ERT | localX | RT_MALLOC
| VCAST_FLUSH_DATA |
false | localXdis | rtInf | vector |
FALSE | localXdot | rtMinusInf |
Some identifiers from the C/C++ standard libraries such as
fprintf
, freadf
, and I
are also
reserved.
If you include these names in your MATLAB code as identifiers, they are renamed in the generated code by prepending
a letter in front of the name. For example, asm
might be renamed as
b_asm
.
This code snippet uses an input and output variable that is named
real_T
, which is a reserved keyword for code generation.
function real_T = foo(real_T) real_T = real_T + 1; end
In the generated code, the variable real_T
is renamed to
b_real_T
.
void foo(double *b_real_T) { (*b_real_T)++; }
Reserved Prefixes
MATLAB
Coder™ reserves the prefix eml
for global C/C++ functions and
variables in generated code. For example, MATLAB for code generation run-time library function names begin with the prefix
emlrt
, such as emlrtCallMATLAB
. To avoid naming
conflicts, do not name C/C++ functions or primary MATLAB functions with the prefix eml
.
MATLAB Coder Code Replacement Library Keywords
The list of code replacement library (CRL) reserved keywords for your development environment varies depending on which CRLs currently are registered. Beyond the default ANSI®, ISO®, and GNU® CRLs provided with MATLAB Coder software, additional CRLs might be registered and available for use if you have installed other products that provide CRLs (for example, a target product), or if you have used Embedded Coder® APIs to create and register custom CRLs.
To generate a list of reserved keywords for the CRLs currently registered in your environment, use the following MATLAB function:
crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers()
This function returns a cell array of character vectors that contain CRL keywords. Specifying the return argument is optional.
Note
To list the CRLs currently registered in your environment, use the MATLAB command crviewer
.
To generate a list of reserved keywords for the CRL that you are using to generate code, call the function passing the name of the CRL as displayed in the Code replacement library menu on the Code Generation > Interface pane of the Configuration Parameters dialog box. For example,
crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers('GNU99 (GNU)')
Here is a partial example of the function output:
>> crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers('GNU99 (GNU)') crl_ids = 'exp10' 'exp10f' 'acosf' 'acoshf' 'asinf' 'asinhf' 'atanf' 'atanhf' ... 'rt_lu_cplx' 'rt_lu_cplx_sgl' 'rt_lu_real' 'rt_lu_real_sgl' 'rt_mod_boolean' 'rt_rem_boolean' 'strcpy' 'utAssert'
Note
Some of the returned keywords appear with the suffix $N
, for
example, 'rt_atan2$N'
. $N
expands into the
suffix _snf
only if nonfinite numbers are supported. For example,
'rt_atan2$N'
represents 'rt_atan2_snf'
if
nonfinite numbers are supported and 'rt_atan2'
if nonfinite
numbers are not supported. As a precaution, you should treat both forms of the
keyword as reserved.
Programmatically Retrieve Lists of Reserved Keywords
Because the list of reserved keywords is large and dynamic, the documentation cannot display it in full. To programmatically retrieve the list of keywords that the code generator attempts to replace, run this command from the MATLAB Command Window:
RTW.reservedIdentifiers()
RTW.reservedIdentifiers
.