Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a CAPL function returning a text string?

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?

like image 442
Dmitry Grigoryev Avatar asked Sep 27 '22 14:09

Dmitry Grigoryev


1 Answers

You have to do it as you would do with string-based functions :

 void ErrorCodeToMsg(char buffer[], int code){
 buffer = myListOfCodes[code];
 }

The value will be stored in the buffer using its reference value. It is not possible to return string in Capl. This is why you can't access String System variables using the @ Selector.

like image 82
PlamZ Avatar answered Oct 06 '22 19:10

PlamZ