Declaring const variable in generated code
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Mike Hosea
2013-11-2
编辑:Mike Hosea
2013-11-2
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 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!