Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAPL typedef bool

Tags:

capl

Does CAPL support something like typedef? My goal is to create a boolean:

    typedef char bool;

I am able to do this:

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

but it isn't what I was going for because I have to do:

      enum bool isValid()

instead of:

      bool isValid()
like image 354
theSparky Avatar asked Jun 20 '26 17:06

theSparky


1 Answers

Unfortunately there is no typedef in CAPL.
enum is the closest you can get regarding boolean values.

The following code shows the usage of such 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;
  }
}
like image 192
ratatoskr_ Avatar answered Jun 24 '26 10:06

ratatoskr_



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!