CAPL typedef bool

Поддерживает ли CAPL что-то вроде typedef? Моя цель - создать логическое значение:

    typedef char bool;

Я умею это делать:

      enum bool {
        false = 0,
        true  = 1
      };

но это не то, к чему я стремился, потому что я должен делать:

      enum bool isValid()

вместо:

      bool isValid()

person theSparky    schedule 08.03.2017    source источник


Ответы (1)


К сожалению, в CAPL нет typedef.
enum - самое близкое из возможных значений логических значений.

Следующий код показывает использование таких enum:

variables
{
  enum Bool {
    true = 1,
    false = 0
  };
}



on Start {
  enum Bool state; 


  // setting the value
  state = true;


  // accessing the integer value
  write("state (integer value): %d", state); // prints "1"


  // accessing the value identifier
  write("state (value identifier ): %s", state.name()); // prints "true"


  // usage in if-statement
  if (state == true) {
    write("if-statement: true");
  } else {
    write("if-statement: false");
  }


  // usage in switch-statement  
  switch (state) {
    case true:
      write("switch-statement: true");
      break;
    case false:
      write("switch-statement: false");
      break;
    default: 
      write("switch-statement: undefined");
      break;
  }
}
person ratatoskr_    schedule 10.03.2017