Simulink Embedded Coder Zero Initialization of Local Variables Not Working

15 次查看(过去 30 天)
Hello, I am using Embedded Coder on Simulink Model (MATLAB 2022B). I want Local variables of generated code to be initialized to zero. I already unticked 'Remove root level I/O zero initialization' and 'Remove internal data zero initialization' so code shouldn't optimize initializations. These two settings initialize Global variables to zero, but don't initialize Local variables to zero. There is an example of generated code and how I want it to be. How can I do it? Thanks for your help.
How it is:
void step_function(uint16_t in1, uint16_t in2)
{
uint16_t Divide;
uint16_t UnitDelay1;
...
How it should be:
void step_function(uint16_t in1, uint16_t in2)
{
uint16_t Divide = 0;
uint16_t UnitDelay1 = 0;
...

回答(1 个)

Akshat Dalal
Akshat Dalal 2024-8-16,10:12
编辑:Akshat Dalal 2024-8-16,10:12
Hi Furkan,
There can still be some other optimizations which can remove the zero-initialization code. You could either disable all optimizations, or a simpler approach would be unset the 'RemoveLocalVariableInitialization'. This would ensure no optimization removes the zero-initialization.
However, this is introduced in R2023b version of MATLAB. I would suggest you to update to R2023b or later releases to avail this feature.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by