Skip to content

Type Casts

Sometimes it is useful to directly cast a type to another one. Spice offers type casting for some type combinations. Additionally, the casting operator can always be applied when the source type matches the cast destination type.

Usage

Casting an int to the short data type:

Spice
int intVar = 12;
short shortVar = (short) intVar;

Example for casting for a function call:

Spice
1
2
3
4
5
6
7
8
9
p testProc(char c, long l) {
    printf("Char was: %c, long was: %d", c, l);
}

f<int> main() {
    int i = 1234567;
    short s = 65s;
    testProc((char) s, (long) i);
}