Windows:BOOL有多大? [英] Windows: How big is a BOOL?

查看:169
本文介绍了Windows:BOOL有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows BOOL 数据类型有多大(以 bits 位)?

How big (in bits) is a Windows BOOL data type?

Microsoft定义 BOOL 数据类型为:

Microsoft defines the BOOL data type as:

BOOL  Boolean variable (should be TRUE or FALSE).
      This type is declared in WinDef.h as follows:

      typedef int BOOL;

将我的问题转换为:

int 数据类型有多大(以位为单位)?

How big (in bits) is an int data type?


在K& R之前.


In before K&R.

假装,我们正在创建一种类型化的编程语言和编译器.您有一个表示逻辑上为 True False 的类型.如果您的编译器也可以链接到Windows DLL,并且您想调用需要 BOOL 数据类型的API,那么您将传递/返回您语言中的哪种数据类型?

Pretend we're creating a typed programming language, and compiler. You have a type that represents something logically being True or False. If your compiler can also link to Windows DLLs, and you want to call an API that requires a BOOL data type, what data type from your language would you pass/return?

为了与Windows BOOL数据类型互操作,您必须知道BOOL的大小.问题将转换为 int 的大小.但这是C/C ++ int,而不是我们假装语言中的 Integer 数据类型.

In order to interop with the Windows BOOL data type, you have to know how large a BOOL is. The question gets converted to how big an int is. But that's a C/C++ int, not the Integer data type in our pretend language.

因此,我需要查找或创建与int大小相同的数据类型.

So i need to either find, or create, a data-type that is the same size as an int.

注意:在我最初的问题中,我没有创建编译器.我从非C/C ++语言调用Windows,因此我需要找到一种与Windows期望大小相同的数据类型.

Note: In my original question i'm not creating a compiler. i'm calling Windows from a language that isn't C/C++, so i need to find a data type that is the same size as what Windows expects.

推荐答案

int 是正式的整数类型,它大于或等于short int类型的大小,而小于或等于到长型的大小."它可以是任何大小,并且是特定于实现的.

int is officially "an integral type that is larger than or equal to the size of type short int, and shorter than or equal to the size of type long." It can be any size, and is implementation specific.

在Microsoft当前的编译器实现中,它是4个字节(32位)(这是特定于编译器的,而不是特定于平台的).您可以在基本类型(C ++) MSDN页面(在底部附近).

It is 4 bytes (32 bits), on Microsoft's current compiler implementation (this is compiler specific, not platform specific). You can see this on the Fundamental Types (C++) page of MSDN (near the bottom).

基本类型的大小

Type                    Size
======================= =========
int, unsigned int       4 bytes

这篇关于Windows:BOOL有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆