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()
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;
}
}