Array as a #define instead of scalar

2 vues (au cours des 30 derniers jours)
Jonas le 23 Avr 2020
Commenté : Jonas le 27 Avr 2020
Hi all
I want to use a small array as a Storage Class 'define':
However, when I use this in my model and try to generate code, it gives the following error:
So it seems I cannot use an array as a #define in code. Is this to be expected? Is there a work-around?
With kind regards,

Réponse acceptée

Ganesh Regoti
Ganesh Regoti le 27 Avr 2020
Hi Jonas,
The error thrown is an expected behaviour.
To work around this issue, you can
  1. Use the "ImportedDefine" Storage class and write a header file to define the array. You will be able to specify the header file from the Model Explorer under Code Generation options > Custom attributes. In this way, Simulink will depend on the header file to provide the definition for "CS_READ_FW_VERSION" and not generate macro directives. Inside the header file you define a constant array such as "const double CS_READ_FW_VERSION[] = {82, 86};"
  2. Use the "Const" Storage class instead of "Define"
Hope this helps!
  1 commentaire
Jonas le 27 Avr 2020
Hi Ganesh, thank you for your reply.
I think I will use the 'Const' storage class. This will provide me with better traceability since I can define the variable in my Data Dictionary, and can use the same naming without danger of conflicts in the naming in my model. The only downside is that the 'const' will use a memory space and it will not be inlined in the code such as a 'define' would.
With kind regards,

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by