#3596 closed defect (fixed)
Using a c keyword as a Modelica variable name doesn't work
Reported by: | Owned by: | Lennart Ochel | |
---|---|---|---|
Priority: | high | Milestone: | 1.9.4 |
Component: | Code Generation | Version: | |
Keywords: | reserved keyword | Cc: |
Description
I created a model with a parameter called "switch" in it. The compilation failed because it gets translated into C in [Model]_functions.c without mangling the name at all, and "switch" is a reserved keyword in C.
Change History (8)
comment:1 by , 9 years ago
comment:3 by , 9 years ago
Ah, sorry, there appears to be more to it than that. You need to create a record containing the parameter switch. I'm using OpenModelica 1.9.3. The following model should reproduce it:
model BaseModel record Config parameter Boolean switch = true; end Config; Config config; end BaseModel;
which generates the following c code in functions.c:
#include "OMTest.BaseModel_functions.h" #ifdef __cplusplus extern "C" { #endif #include "OMTest.BaseModel_literals.h" #include "OMTest.BaseModel_includes.h" /* Next line uses "switch" with no leading underscore */ OMTest_BaseModel_Config omc_OMTest_BaseModel_Config(threadData_t *threadData, modelica_boolean switch) { OMTest_BaseModel_Config tmp1; tmp1._switch = switch; return tmp1; } modelica_metatype boxptr_OMTest_BaseModel_Config(threadData_t *threadData, modelica_metatype _switch) { return mmc_mk_box2(3, &OMTest_BaseModel_Config__desc, _switch); } #ifdef __cplusplus } #endif
comment:6 by , 9 years ago
Milestone: | Future → 1.9.4 |
---|
Note:
See TracTickets
for help on using tickets.
I cannot reproduce this for the c runtime, but the code for the Cpp runtime seems to be invalid since the variables get translated into C++ as they are in the model (OMCppMFunctions.cpp).
Can you provide a small test case? In my example, the variable
switch
get a underscore as prefix in the generated code ([Model]_functions.c).