Declaring const variable in generated code

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

Antworten (1)

Mike Hosea
Mike Hosea am 2 Nov. 2013
Bearbeitet: Mike Hosea am 2 Nov. 2013

1 Stimme

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.

Kategorien

Mehr zu MATLAB Coder finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 9 Aug. 2013

Bearbeitet:

am 2 Nov. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by