Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3596 closed defect (fixed)

Using a c keyword as a Modelica variable name doesn't work

Reported by: Sam.Lishak@… 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 Lennart Ochel, 9 years ago

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).

comment:2 by Adrian Pop, 9 years ago

Can you tell us also what OpenModelica version are you using?

comment:3 by Sam.Lishak@…, 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:4 by Lennart Ochel, 9 years ago

Status: newaccepted

I see! Thanks for reporting this issue.

comment:5 by Lennart Ochel, 9 years ago

Resolution: fixed
Status: acceptedclosed

Fixed in 2d0bc6b.

comment:6 by Lennart Ochel, 9 years ago

Milestone: Future1.9.4

comment:7 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.