Dmi*_*yev 5 string syntax capl
我在 Vector CANoe 中开发了 CAPL 脚本,我需要定义几个返回文本字符串的函数。在 C 中,我会这样写:
char * ErrorCodeToMsg(int code)
Run Code Online (Sandbox Code Playgroud)
或者
char [] ErrorCodeToMsg(int code)
Run Code Online (Sandbox Code Playgroud)
在 CAPL 中,两个定义都失败并带有parse error
. 到目前为止,我想出的唯一可行的解决方案是:
variables {
char retval[256];
}
void ErrorCodeToMsg(int code) {
char [] msg = "Hello word";
strncpy(retval, msg, 256);
}
Run Code Online (Sandbox Code Playgroud)
当然这很丑陋,因为每次调用都ErrorCodeToMsg
需要两条语句而不是一条语句。有没有更好的办法?
小智 4
您必须像使用基于字符串的函数一样执行此操作:
void ErrorCodeToMsg(char buffer[], int code){
buffer = myListOfCodes[code];
}
Run Code Online (Sandbox Code Playgroud)
该值将使用其参考值存储在缓冲区中。Capl 中不可能返回字符串。这就是为什么您无法使用@
选择器访问字符串系统变量的原因。
归档时间: |
|
查看次数: |
18040 次 |
最近记录: |