I develop CAPL scripts in Vector CANoe, and I need to define several functions returning text strings. In C, I would write something like this:
char * ErrorCodeToMsg(int code)
or
char [] ErrorCodeToMsg(int code)
In CAPL, both definitions fail with a parse error
. The only working solution I came up with so far is:
variables {
char retval[256];
}
void ErrorCodeToMsg(int code) {
char [] msg = "Hello word";
strncpy(retval, msg, 256);
}
Of course this is very ugly, because each call to ErrorCodeToMsg
requires two statements instead of one. Is there a better way?
char *
return value to be able towrite("Error: %s", ErrorCodeToMsg(errno))
, thanks for confirming it's not going to happen. – Fettling