English 中文(简体)
把一个空白点推向一个未签名的长处
原标题:Converting a void pointer to an unsigned long

我正在制定一项C方案,该方案的出发点是,我知道某个事实表明存在愤怒,但我无法说明如何正确对待这种愤怒。 例如,以下措施将产生C6011警报。

int convert(PVOID val) 
{
   int value = *((int *) val); 
   return value;
}

然而,我计划在我的凯里图车司机中使用这一警告,将是一个问题,我确实需要把人民民主力量组织变成一个非政府组织联盟,以便我能够将其与另一个非政府组织进行比较,但我并不肯定如何这样做。 当我印刷该真空点的价值时,它把这个价值作为“ULONGLONG”加以印刷,但当我需要时,则以黑体字印制,以便比较和印刷这一价值。

下面的法典将产生C222的错误和C4047的警告,因为它不喜欢我给非政府组织留下一个空白点,但我并不肯定,在不产生任何警告、错误或BSOD的情况下如何这样做。

bool same(PVOID val, ULONGLONG otherVal) 
{
   ULONGLONG value = val;
   return value == otherVal;
}
问题回答

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,但该法典仍然有坏的轮.。 我不知道使这种比较(种子)适当的情况,但可能有一种更清洁的办法。

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.

你的法典援引未经界定的行为(UB),因为它违反了严格的条款。

您应始终使用<代码>mcpy的功能。

int foo(void *ptrToInt)
{
    int val;
    memcpy(&val, ptrToInt, sizeof(int));
    return val;
}

如有可能,任何现代汇编者将取消<代码>mcpy功能电话。


Anyways the following code will produce a C222 error and a C4047 warning because it does not like me casting a void pointer to a ULONGLONG but I am not sure how to do this without generating any warnings, errors, or BSOD s.

你不担任你的职务。 如果您想将点子转换到星体上,请使用<代码>uintptr_t。 类型。

bool same(void *val, uintptr_t otherVal) 
{
   return (uintptr_t)val == otherVal;
   //      ^^^^^^^^^ - this is cast
}




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签