For code generation, integer arguments corresponding to the conversion character '%d' must be representable in the target hardware.
3 views (last 30 days)
Show older comments
I'm pretty new to Matlab and Simulink, particularly configurations. While generating code in the simulink coder I've come across a problem based on this line.
[newChar, numCharsRead] = fscanf(fid, '%c',1)
For code generation, integer arguments corresponding to the conversion character '%d' must be representable in the target hardware. The provided argument is 64 bits while the largest integer in the specified hardware is 32 bits.
The target is a 32bit machine and the manufacturer provides the .tlc we are using. I don't see anything within the configuration set to 64 bit.
Any ideas as to where I should dig to find the cause of this issue would be appreciated.
0 Comments
Answers (1)
Harsh
on 26 Mar 2025
In MATLAB, numeric variables are by default stored as 64-bit (8-byte) double-precision floating-point values. This default behavior can lead to compatibility issues when generating code for target hardware that only supports 32-bit integers. In such cases, every integer argument used in the code must be explicitly matched to the hardware’s supported size.
In your specific case, the issue arises from the line:
[newChar, numCharsRead] = fscanf(fid, '%c', 1);
Here, the integer "1" is treated as a 64-bit value by default, which is incompatible with your 32-bit target hardware. To address this, you should explicitly cast the "1" to a 32-bit integer using "int32", like this:
[newChar, numCharsRead] = fscanf(fid, '%c', int32(1));
This explicit casting ensures that the code is compatible with the 32-bit architecture of your target machine.
For more detailed information about the default numeric types in MATLAB, you can refer to the following documentation - www.mathworks.com/help/matlab/matlab_external/default-numeric-types-in-matlab-and-python.html
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!