Declaring const variable in generated code
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I'm trying to generate in matlab C-code that declare and define with const value a variable, e.g.: 'const int variable = 4;'
I want it to be visible from other C-file (not generated) via 'extern' keyword.
The problem is that without further using variable in matlab source The Coder omitt putting it's declaration at all.
Using coder.opaque('int', '4') also don't help. Declaring is as 'global' unfortunally as well.
Can I do this other way than filling 'Custom C code...' field? I believe it's an 'ugly' way to do that.
I have matlab 2012b
0 comentarios
Respuestas (1)
Mike Hosea
el 2 de Nov. de 2013
Editada: Mike Hosea
el 2 de Nov. de 2013
This is a common request in one form or another. A common variant is that people would like to have numeric constants #defined rather than folded into the code as literals.
I wish I had a better answer for you today, but the Custom C Code solution is what I would probably do. I might write a build script that generated a header "on the fly" based on the current setting to keep things from getting out of sync. The build-script can also save the current value to a .mat file, which can then be loaded from withing the function(s) being compiled using coder.load.
0 comentarios
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!