XMOS XC: A pointless language?
October 23, 2009
No pun here, this seems to be fact. XC does NOT support pointers, struct bitfields, floats, long long math, or goto. Technically this makes it a pointless language. Ok i’m done playing around(don’t take this the wrong XMOS guys) I’ll quote from “Programming XC on XMOS Devices” page 14/139 section 1.6:
“XC provides many of the same capabilities as C, the main omission being support for pointers. Consequently, many programming errors that are undefined in C are knownto be invalid in XC and can be caught either by the compiler or raised as run-time exceptions. All of XC’s data types and operators have the same meaning as in C, and user-defined types including structures, unions, enumerations and typedefs are also supported. The extensions for pass-by-reference parameters and multiple-return functions provide support for operations usually performed using pointers in C. XC’s scope and linkage rules are the same as with C, and both languages use the same
preprocessor. XC does not support floating point, long long arithmetic, structure bit-fields or volatile data types, and no goto statement is provided. These restrictions may be relaxed in future releases to improve compatibility between languages.”
Ok, so they only axed the head of pointers, we still have the ability to pass by reference and apparently it is illegal to pass more than one value of the same object so XC is a semi-rigid language. XC REQUIRES that case statements terminate with either BREAK or RETURN. Another thing that caught my attention was multiple function returns. 13/139 section 1.4.3: “A function may be declared as returning more than one value” This renders the following code block legal in XC.
{int , int} swap (int a, int b)
{
return {b, a};
}
void main ( void ){
int a = 1;
int b = 2;
{a, b} = swap (b, a);
}
More thatnone return value, neat.
February 21, 2010 at 3:00 pm
“No pun here, this seems to be fact. XC does NOT support pointers, struct bitfields, floats, long long math, or goto. Technically this makes it a pointless language.”
That is a strong claim. I wouldn’t really call it a ‘fact’. Is your emphasis on pointers based on sentiment or do you have empiric evidence? And goto? What’s your arsenal to argue against Dijkstra on goto?
February 21, 2010 at 10:32 pm
Provocative, but you almost seem to come down on the other side. Note that XC is designed to be a “safe” language. For example, arrays have to be of fixed size, they cannot be resized in XC – this means the compiler is able to put in bounds checking for you, preventing you from doing silly stuff. So I guess comparing XC and C is like comparing rock climbing with and without rope…
Its also the superset of stuff that XC adds which is nice – stuff like the I/O, channels and parallelism. Of course you can do all this stuff through library function calls and have an API to the architecture – but that wouldn’t result in such elegant or readable code.