Search code examples
cmatlabgccmingwmatlab-coder

Variable named i386 generated by Matlab Coder


I'm generating code for a function with several variable-sized arrays. The code needs to be compiled in both linux (with gcc) and windows machines (with MinGW).

To "ensure capacity" in those variables, Matlab creates several counter variables, named i349, i350, ..., i386, ... i400. Apparently, the windows compiler doesn't like this. It throws two errors that say :

line x: error: expected identifier or '(' before numeric constant

line y: error: lvalue required as left operand of assignment

line y+1: error: lvalue required as increment operand

These are all solved by manually picking other variable names. While I could use some script to automatically do so, I'd rather avoid it.

Two questions:

  1. Why does these variable names cause a problem with the compiler?

  2. How can I tell Matlab not to generate variables with these names?


Solution

  • Why does these variable names cause a problem with the compiler?

    These are predefined macros by the compiler. It's nonstandard behavior, but this is used for backwards compatibility in determining what system the code is being compiled for.

    How can I tell Matlab not to generate variables with these names?

    You don't want to. Instead, pass a -std=c... option to the compiler to have it act in standard-compliant mode.