哪个C/C++头文件定义了BYTE数据类型?

and*_*and 24 c c++ windows

我正在使用此声明移植标头:

 struct tMaterialInfo {     
    char strName[255]; // the texture name
    char strFile [255]; // the texture
     BYTE color [3]; // the color of the object 
 };
Run Code Online (Sandbox Code Playgroud)

标题包含以下内容:

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <vector>
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include<gl\glu.h>// Header File For The GLu32 Library
#include <gl\glaux.h>
Run Code Online (Sandbox Code Playgroud)

BYTE来自哪里?

dso*_*ano 26

我猜这是来自Windows.

一个字节(8位).

此类型在WinDef.h中声明如下:

typedef unsigned char BYTE;

  • 如果您使用的是WINAPI函数,则应使用Windows数据类型.http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/c066968d-8cb7-4e5a-9807-aa9cd47c65ed (10认同)
  • 应该补充一点,不应该使用它.所有全局大小写整数/字符串类型都是无用的代码 - uglification,只能使代码不必要地与Windows绑定.只需使用相应的标准类型,如`unsigned char`或`uint8_t`(如果后者存在则必须相同). (5认同)

小智 11

如果您正在为Windows编程C,我假设您正在使用Visual Studio进行开发.您可以右键单击任何关键字,然后选择" 转到定义" F12以查找其定义位置.

BYTE在WinDef.h中定义

typedef unsigned char       BYTE;
Run Code Online (Sandbox Code Playgroud)


RBe*_*eig 5

几乎可以肯定,从包含的众多标题之一windows.h.Windows SDK包含typedefs for BYTE,WORDDWORD至少Windows 2.0天(我记得最早的Windows SDK).