Borrar filtros
Borrar filtros

C++ code generation: is it possible to put struct declaration in a namespace?

7 visualizaciones (últimos 30 días)
fraben
fraben el 29 de Sept. de 2022
Comentada: Daniel Paukner el 9 de Ag. de 2024 a las 20:16
Hello,
I am generating C++ code using Embedded Coder in v2021b. I am able to put the generated class in my chosen namespace via the Code Interface dialog:
But in my model i am using various buses, which are translated in C++ structs, which in turn reside in the global namespace.
Is there a way to specify a namespace for these structs too?

Respuestas (1)

Yoga
Yoga el 10 de Sept. de 2023
I understand that you want to specify a namespace for structs that result out of the various buses you use in the model. This is possible by interactively configuring the C++ resultant code.
I hope this helps resolve your issue.
  2 comentarios
fraben
fraben el 13 de Sept. de 2023
Hello Yoga,
Thanks for your answer! I skimmed through the page you linked, but it seems to be only possible to wrap the model's class in a namespace.
I already did that, but from what i understand i can't control the namespace which will contain the structs corresponding to the buses entering/exiting the model: they, indeed, reside in the global namespace.
Daniel Paukner
Daniel Paukner el 9 de Ag. de 2024 a las 20:16
I have a similar problem.
I define a class namespace using the interactive method stated on the site mentioned by Yoga, and it is used for the generated code of the model class.
But i also define input & output busses, and in those, i reference external enum definitions. I converted the enums from my C++ header using simulink.importExternalCTypes() and the enums work when i test my model in simulink. But when i code the model, the bus definitions get written into codermodel_types.h and are not nested within the namespace of the parent model. My external enum definition did however specify the enums in a namespace for name collision reasons.
When i add the line "using namespace <mynamespace>" in codermodel_types.h, it compiles without a hitch, but i need to manually add that. How do i get simulink embedded coder to add that line for me, or even better, drop ALL the code it creates into the namespace i give it?

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by