I am working on a C program that takes in a void pointer that I know
for a fact points to an integer but I cant figure out how to correctly
cast it to such. For example, the following will produce a C6011
warning.
int convert(PVOID val)
{
int value = *((int *) val);
return value;
}
根据错误编号的格式,我猜测你与MSVC. 。 很显然,MSVC并不肯定,因为你实际上把点人指向愤怒。 你的文 cast和文.;参考是找到点人点的<条码>的正确途径。 它只是警告,但你应该能够在放弃之前进行无效检查,从而保持沉默。
int convert(PVOID val) {
if (val == NULL) {
// abort or return a default value
} else {
return *((int *) val);
}
}
However, I plan to use this in my kernel driver so warnings will be a problem and I really need to cast the PVOID into a ULONGLONG so that I can compare it to another ULONGLONG but I am not sure how to do that.
That sounds suspect, but if you intend to do it then you do exactly what you describe: cast, via a cast operator. C explicitly allows such conversions.
下面的法典将产生C222的错误和C4047的警告,因为它不喜欢我给非政府组织留下一个空白点,但我并不肯定,在不产生任何警告、错误或BSOD的情况下如何这样做。
A C4047 makes sense, but I have no idea what a C222 is. I do not find it documented. In any case, standard C permits you to convert pointers to integers, but such conversions are not implicit. A cast is required:
bool same(PVOID val, ULONGLONG otherVal) {
return otherVal == (ULONGLONG) val;
}
然而,虽然这应当明确C4047,但该法典仍然有坏的轮.。 我不知道使这种比较(种子)适当的情况,但可能有一种更清洁的办法。