在所有的Windows平台上是一个浮点数4字节 [英] Is a float 4 bytes on all windows platforms

查看:416
本文介绍了在所有的Windows平台上是一个浮点数4字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用c ++编写一个程序,它将不同的数据存储在二进制文件中。我遇到了问题,因为数据类型的大小可以从一个系统更改为另一个。我想知道在所有的Windows平台上,花车总是4字节。我建立这个程序的唯一平台是windows。

解决方案

Windows没有定义 float - 你的编译器定义了这个。

windef.h中定义的是一个名为 FLOAT 的类型。它被定义为 typedef float FLOAT; 。这是Win32 API使用的类型名称,以及如果Windows支持对您很重要,应该使用的名称。我怀疑任何Windows编译器都不会改变 float 类型的格式,但微软肯定可以将 typedef 更改为 FLOAT ,这将改变在所有版本的Windows上支持 float 的意思。


I am writing a program in c++, that stores different data in a binary file. I am running into issues because the size of a data type can change from one system to another. I was wondering if floats are always 4 byte on all windows platforms. The only platform i am building this program for is windows.

解决方案

Windows does not define the size of float -- your compiler defines that.

What Windows defines is a type named FLOAT in windef.h. It's defined as typedef float FLOAT;. That's the type name the Win32 API uses and the one you should be using if Windows support is important to you. I doubt any Windows compiler will ever change its format for float types, but Microsoft certainly could change their typedef for FLOAT and that would change what it means to support float on all versions of Windows.

这篇关于在所有的Windows平台上是一个浮点数4字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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