Engineering System Design

 View Only
  • 1.  Enum redeclaration conflict during code generation

    Posted Fri March 24, 2023 04:03 AM

    Hello,

    I have a problem with enum redeclaration compiler error during simulation. 

    Basically I have defined two enumeration as ValueTypes:

    • Enumeration1 with literals "Success", "ErrorTimeout" 
    • Enumeration2 with literals "Success", ErrorTimeout"

    The code generated (C++) looks like:

    enum Enumeration1 {

       Success = 0,

       ErrorTimeout = 1

    };

    and 

    enum Enumeration2 {

       Success = 0,

       ErrorTimeout = 1

    };

    Which leads to the compiler error "Redeclaration of 'Success'  for the second enumeration. Usually I would solve such problems with defining 

    enum class Enumeration1 { ...} and enum class Enumeration2 {...}. 

    Indeed, code is generated from Rhapsody automatically, so how can I activate that the compiler creates scoped enumeration? Is this possible at all?

    Best regards

    Robert



    ------------------------------
    Robert Fromm
    ------------------------------


  • 2.  RE: Enum redeclaration conflict during code generation

    Posted Mon March 27, 2023 02:40 AM

    I am also curious about this. I usually solve it by making the enumeration names unique by adding a suffix. In this case since the name of the ValueType was Enumeration1 and Enumeration 2, I would had named the enumerations Success_1 and Success_2 respectively.

    I asked the same question on Burce's forum here and he also makes the names unique.



    ------------------------------
    Markus Nordstrand
    ------------------------------



  • 3.  RE: Enum redeclaration conflict during code generation

    Posted Mon March 27, 2023 02:56 AM

    Hello Markus,

    thanks for the feedback.

    Basically this would be a solution. Indeed, our architecture defines quite a great amount of enumeration. Indeed yet we did not simulate, so it didn't matter.

    As C++ is capable of scoped enumeration since quite some time. I opened a ticket at IBM so let's see what they answer.

    Best regards

    Robert



    ------------------------------
    Robert Fromm
    ------------------------------



  • 4.  RE: Enum redeclaration conflict during code generation

    IBM Champion
    Posted 27 days ago
    Edited by Martin Stockl 27 days ago

    Robert,
    you may want to have a look into the "ModernCpp" profile, which is a nested part inside of the RXF_CPP, but independent of it.
    It adds terminology of C++11, C++14 and C++17 to Rhapsody, in order to use them in code generation.
    It comes as an installable AddOn in Rhapsody v10.0.x or later, but can be added to and used with 9.x versions as well.
    Best regards,
    Martin



    ------------------------------
    [Martin] [Stockl]
    [
    Embedded Real-Time Systems Modeling Specialist]
    [SodiusWillert Germany]
    ------------------------------



  • 5.  RE: Enum redeclaration conflict during code generation

    IBM Champion
    Posted 18 hours ago

    https://www.merlinscave.info/have-multiple-enumerations-with-the-same-literals-using-rhapsody-model-transformations.html



    ------------------------------
    Andy Lapping
    Technical Fellow
    Sodius Willert
    Cwmbran
    ------------------------------



  • 6.  RE: Enum redeclaration conflict during code generation

    IBM Champion
    Posted 10 hours ago

    Yes, this a perfect workaround by extending the existing code generation, if you one does not have the ModernCpp profile available or if an older Embedded C++ Compiler does not support ModernCpp.



    ------------------------------
    [Martin] [Stockl]
    [SodiusWillert Germany]
    [
    Embedded Real-Time Systems Modeling Specialist]
    ------------------------------