由 Matlab Coder 生成的名为 i386 的变量
Variable named i386 generated by Matlab Coder
我正在为具有多个可变大小数组的函数生成代码。代码需要在 linux(使用 gcc)和 windows 机器(使用 MinGW)中编译。
到"ensure capacity"那些变量中,Matlab创建了几个计数器变量,命名为i349
,i350
,...,i386
,...i400
.显然,windows 编译器不喜欢这样。它抛出两个错误:
第 x 行:error: expected identifier or '(' before numeric constant
第 y 行:error: lvalue required as left operand of assignment
第 y+1 行:error: lvalue required as increment operand
这些都是通过手动选择其他变量名来解决的。虽然我可以使用一些脚本来自动执行此操作,但我宁愿避免使用它。
两个问题:
为什么这些变量名会导致编译器出现问题?
如何告诉 Matlab 不要生成具有这些名称的变量?
Why does these variable names cause a problem with the compiler?
这些是编译器预定义的宏。这是非标准行为,但这用于确定代码正在为哪个系统编译时的向后兼容性。
How can I tell Matlab not to generate variables with these names?
你不想。相反,将 -std=c...
选项传递给编译器,使其在符合标准的模式下运行。
如果您遇到无法使用编译器标志修复的名称冲突,您可以将 ReservedNameArray
config setting 与 MATLAB Coder 一起使用:
cfg = coder.config('lib');
cfg.ReservedNameArray = 'Name1;Name2';
codegen foo.m -config cfg
这将导致编码器破坏标识符以不与提供的名称冲突。
我正在为具有多个可变大小数组的函数生成代码。代码需要在 linux(使用 gcc)和 windows 机器(使用 MinGW)中编译。
到"ensure capacity"那些变量中,Matlab创建了几个计数器变量,命名为i349
,i350
,...,i386
,...i400
.显然,windows 编译器不喜欢这样。它抛出两个错误:
第 x 行:error: expected identifier or '(' before numeric constant
第 y 行:error: lvalue required as left operand of assignment
第 y+1 行:error: lvalue required as increment operand
这些都是通过手动选择其他变量名来解决的。虽然我可以使用一些脚本来自动执行此操作,但我宁愿避免使用它。
两个问题:
为什么这些变量名会导致编译器出现问题?
如何告诉 Matlab 不要生成具有这些名称的变量?
Why does these variable names cause a problem with the compiler?
这些是编译器预定义的宏。这是非标准行为,但这用于确定代码正在为哪个系统编译时的向后兼容性。
How can I tell Matlab not to generate variables with these names?
你不想。相反,将 -std=c...
选项传递给编译器,使其在符合标准的模式下运行。
如果您遇到无法使用编译器标志修复的名称冲突,您可以将 ReservedNameArray
config setting 与 MATLAB Coder 一起使用:
cfg = coder.config('lib');
cfg.ReservedNameArray = 'Name1;Name2';
codegen foo.m -config cfg
这将导致编码器破坏标识符以不与提供的名称冲突。