Code: (running on CANoe 8.5.98 32bit)
/*@!Encoding:1252*/
includes {
}
variables {
/* Windows HRESULT error type enum. */
enum HRESULT_Types {
S_OK /* Operation successful */ = 0x00000000,
S_FALSE /* No error occured, oper. unsuccessful */ = 0x00000001,
E_NOTIMPL /* Not implemented */ = 0x80004001,
E_NOINTERFACE /* No such interface supported */ = 0x80004002,
E_POINTER /* Pointer that is not valid */ = 0x80004003,
E_ABORT /* Operation aborted */ = 0x80004004,
E_FAIL /* Unspecified failure */ = 0x80004005,
E_UNEXPECTED /* Unexpected failure */ = 0x8000FFFF,
E_ACCESSDENIED /* General access denied error */ = 0x80070005,
E_HANDLE /* Handle that is not valid */ = 0x80070006,
E_OUTOFMEMORY /* Failed to allocate necessary memory */ = 0x8007000E,
E_INVALIDARG /* One or more arguments are not valid */ = 0x80070057
};
msTimer Timer10ms;
}
on start {
setTimer(Timer10ms, 10);
}
on timer Timer10ms {
long hr = S_OK;
hr = func1();
if(hr == S_OK) {
setTimer(Timer10ms, 10);
}
}
long func1() {
return S_OK;
}
Compiler error:
系统L7,C3:操作数类型不兼容 .
What have I done so far:
-
我没有任何S_OK的双重声明 .
-
我试着评论S_OK枚举,编译器说
unknown symbol 'S_OK'
我在代码中写了S_OK . -
我可以编写
SS_OK
而不是S_OK
并且编译时没有错误 . -
我可以写
S_OK = 0
并出现相同的错误 . -
我可以写
S_OK, ...
并出现相同的错误 .
Good to know:
我已经构建了一个dll,它实现了从Windows API到我的CANoe环境的一些功能 . 当然有S_OK的typedef,但我无法访问任何其他typedef或全局变量,因为CAPL dll非常严格 . 这就是为什么我想实现这个简单的枚举 .
有人可以解释为什么编译器不想正确编译它吗?我不知道,这个错误对我来说似乎很奇怪(定义中的不兼容类型 ¯\_(ʘ ͟ʖʘ)_/¯
) .
1 回答
问题是
func1()
返回long
,但S_OK
是枚举常量 . 因此错误“操作数类型是不兼容的” . 以下是修复错误的两个选项:S_OK
至long
:enum HRESULT_Types
:您还可以声明/定义与枚举类型关联的变量: