0

I want to make it so that I can use the same enum member name in different enumerations, like this:

enum OPTION_1
{
    ACTIVATED   = 1,
    DEACTIVATED = 0
};

enum OPTION_2
{
    ACTIVATED   = 1,
    OFF         = 0
};

When I try to compile this I get the error: Duplicate enumerator name "ACTIVATED".

I have found a similar question, but for the C++ language c++ how to have same enum members name in different enum names without getting err:redefinition; previous definition was 'enumerator'

I tried the solutions showed there, but I couldn't implement them in CAPL. My question is whether I can have enums with different names but with the same member names; if it is possible, how can it be implemented in CAPL?

Lares
  • 17
  • 1
  • 7

1 Answers1

0

There is a workaround, which is really ugly, no recommendation to do this.

In CANoe you can define own value tables for system variables which are actually enumerations and there is no limit for same members names.

Value Table Editor for CANoe-sysvar

And then you can reuse this enums in CAPL-code:

variables{
  enum VtSv_foo_myEnum1 var1;
  enum VtSv_myEnum2 var2;
}

do_foo(){
  var1 = (enum VtSv_foo_myEnum1) sysvar::foo::myEnum1::One;
  var2 = (enum VtSv_myEnum2) sysvar::myEnum2::One;  
}

Before starting to use this just ask yourself where is the benefit? Because the code will looks very messy.

And you can find more in the CANoe-help:

CAPL Introduction » Basics » Enumeration Types

An Other
  • 331
  • 1
  • 7