(BYTE)-1是什么意思 [英] what does it mean by (BYTE)-1
本文介绍了(BYTE)-1是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在读别人的代码:
#define CPUTYPE_INVALID ((BYTE)-1)
这是什么意思?我想它有相同的效果,如下,
What does that mean? I guess it has the same effect as follows ,
#define CPUTYPE_INVALID 255
如果我们已经有
typedef unsigned char BYTE; (in windef.h)
推荐答案
以下假设BYTE是一个类型,因为您在windef.h中写入它)
假设 BYTE
= char
,因为它转换 -1
,所以它产生 -1
(整数)作为 char
。
Assuming BYTE
= char
, this yields -1
since it's converting -1
(integer) as a char
. It's just a C-style cast for -1.
这是一种在系统定义的 BYTE
类型,无论是有符号还是无符号(在这种情况下,它是最大可表示的)。在签名的情况下,为了指示伪造条目,使用-1值(或者当您有有限数量的条目时是极端值)是一种常见做法。
It's a way of getting "-1" in the system-defined BYTE
type, either signed or unsigned (in that case it's the maximum representable). In the signed case, to indicate a bogus entry, it's a common practice to use a -1 value (or an extreme one when you have a limited number of entries)
#include <iostream>
#include <string>
using namespace std;
#define BYTE char
#define CPUTYPE_INVALID ((BYTE)-1)
#define BYTE2 unsigned char
#define CPUTYPE_INVALID2 ((BYTE2)-1)
int main() {
cout << to_string(CPUTYPE_INVALID); // -1
cout << to_string(CPUTYPE_INVALID2); // 255
return 0;
}
这篇关于(BYTE)-1是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文