For code generation problem
3 次查看(过去 30 天)
显示 更早的评论
When generation code for the attachment model, i find that the united delay block is generated as reachable variables in .h file, as is shown in the attachemnt figure. My question is, if we want to configure the united delay block as globale variables, but without the "extern" word, how to do this?
0 个评论
回答(2 个)
Jeevan Thomas
2015-9-15
If you want to generate the unit delay variable in the model as a global variable, but not as an extern variable means that you would like to configure the unit delay as a static variable (with no declaration in the H file, but scope only in the C file). Open the unit delay block and give a unique name to the state attributes. Then as shown in figure, check the "state must resolve to simulink signal" box.
Now you must create a Simulink.Signal object of the same unique identifier in the Matlab workspace and set the storage class as "FileScope". This tells the code generator that the resolved signal is restricted only to a single file. So extern declarations are not required. Eg: UD = Simulink.Signal; UD.StorageClass = 'FileScope (Custom)'
Build the model/Generate code. You'll find that the delay block is now generated as variable "UD" and it's declared on top of the C file as static.
Hope it helps.
0 个评论
Walter Roberson
2015-9-12
"extern" is C's method for noting global variables. "extern" in C is equivalent to "global" in MATLAB, except for some issues having to do with initializing. If you had something in C that did not use "extern" then it would not be a global.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!