Declaring const variable in generated code

조회 수: 2 (최근 30일)
Matthew
Matthew 2013년 8월 9일
편집: Mike Hosea 2013년 11월 2일
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

답변 (1개)

Mike Hosea
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.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by