【问题标题】:Which C/C++ header file defines a BYTE data type?哪个 C/C++ 头文件定义了 BYTE 数据类型?
【发布时间】:2011-05-28 00:48:42
【问题描述】:

我正在移植带有此声明的标头:

 struct tMaterialInfo {     
    char strName[255]; // the texture name
    char strFile [255]; // the texture
     BYTE color [3]; // the color of the object 
 };

标头包含以下内容:

#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>

那个 BYTE 是从哪里来的?

【问题讨论】:

  • +1 用于清楚地说明问题,并提供足够的上下文以提供有用的答案。

标签: c++ c windows


【解决方案1】:

我猜它来自Windows

一个字节(8 位)。

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

typedef unsigned char BYTE;

【讨论】:

  • 并且应该补充一点,它不应该被使用。所有全大写整数/字符串类型都是无用的代码丑化,仅用于使代码不必要地绑定到 Windows。只需使用相应的标准类型,如unsigned charuint8_t(如果后者存在,则必须相同)。
  • stdint 直到 2010 年才添加到 Visual Studio。
  • 如果您使用的是 WINAPI 函数,您应该使用 Windows 数据类型。 social.msdn.microsoft.com/Forums/en/vcgeneral/thread/…
【解决方案2】:

几乎可以肯定来自windows.h 中包含的众多标头之一。至少从 Windows 2.0 天(我记得最早的 Windows SDK)开始,Windows SDK 就包含了 BYTEWORDDWORDtypedefs。

【讨论】:

    【解决方案3】:

    如果您正在为 Windows 编写 C 语言,我假设您正在使用 Visual Studio 进行开发。您可以右键单击任何关键字并选择Go To Definition F12 以查找它的定义位置。

    BYTE 在 WinDef.h 中定义

    typedef unsigned char       BYTE;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 2015-06-05
      • 2012-04-03
      • 1970-01-01
      • 2013-04-10
      • 2011-07-29
      相关资源
      最近更新 更多