Simulink Embedded Coder Zero Initialization of Local Variables Not Working
8 views (last 30 days)
Show older comments
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;
...
0 Comments
Answers (1)
Akshat Dalal
on 16 Aug 2024
Edited: Akshat Dalal
on 16 Aug 2024
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.
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!