It's very annoying that in xC it is impossible to group stuff (variables, resources, etc.), which logically belongs together, into structs.
The lack of this ability can result ugly codes.
E.g. I'd like to implement some packet based USB communication code for more endpoints. I'd use a structure like this for storing all the info required for handling an endpoint:
Code: Select all
typedef struct {
chanend ch;
XUD_ep outEp;
PtrBuffer freeBuf;
PtrBuffer usedBuf;
server interface ComRxIf rxIf;
} RxDesc;
Unfortunately I cannot place the "chanend" and the "interface" into the struct.
Than what can I do?
1. Don't use structs, just pass every related variables and resources to every handler functions. -> This is ugly and bloated.
2. Implement as much as possible in C and provide xC callouts for the XMOS specific stuff. -> Even more ugly and bloated.
3. ?
I'd rather like to be able to write well structured xC code, than to expect extra safety from the compiler.
Maybe the code safety shouldn't be a compile time issue. The source also could be compiled in some debug mode which would add some run-time safety checkers (of course this approach would require deep testing which is an extra job).