uint32_t的VS INT作为日常编程公约 [英] uint32_t vs int as a convention for everyday programming

查看:202
本文介绍了uint32_t的VS INT作为日常编程公约的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应在使用的数据类型从stdint.h?
那么,是否可以始终是作为约定他们使用?
什么是大小非特异类型,如int和短?

设计的目的
解决方案

  

当应在使用的数据类型从stdint.h?



  1. 当编程任务特别指定整数宽度以适应某些文件或通信协议格式。

  2. 在当前高度的可移植性的平台之间需要过的性能


  

是不是总是按照惯例他们(当时)使用?


事情倚的方式。固定宽度类型是一个较新的除了C.原来的C有的char,short,int和长的是进步的,因为它试图,而不的具体,以适应在各种不同的处理器和环境的各种可用的整数大小。由于C是40ish岁,它说该战略的成功。大部分C code已经被写入并成功地与软整数规格尺寸对应。随着越来越多的一致性需求,的char,short,int和长,很长很长,是不够的(或至少不那么容易)等中int8_t ,int16_t,int32_t和的int64_t 的诞生。新的语言往往需要非常特定的固定大小的整数类型和2的补码。由于他们是成功的,即达尔文pressure会推C.我的水晶球说,我们将看到一个缓慢的迁移在C增加固定宽度类型的用途。


  

什么非特异性大小类型,如int和短的设计的目的是什么?


这是一个良好的开端,以适应各种不同的整数宽度(8,9,12,18,36等)和编码(2的,1的,标志/ MAG)的。这么多的编码采用当今功率为2的大小与整数2的补,一个可能没有意识到,很多其他的安排事先存在。见previous答案也。

When should one use the datatypes from stdint.h? Is it right to always use as a convention them? What was the purpose of the design of nonspecific size types like int and short?

解决方案

When should one use the datatypes from stdint.h?

  1. When the programming tasks specify the integer width especially to accommodate some file or communication protocol format.
  2. When high degree of portability between platforms is required over performance.

Is it right to always use as a convention them (then)?

Things are leaning that way. The fixed width types are a more recent addition to C. Original C had char, short, int, long and that was progressive as it tried, without being too specific, to accommodate the various integer sizes available across a wide variety of processors and environments. As C is 40ish years old, it speaks to the success of that strategy. Much C code has been written and successfully copes with the soft integer specification size. With increasing needs for consistency, char, short, int, long and long long, are not enough (or at least not so easy) and so int8_t, int16_t, int32_t, int64_t are born. New languages tend to require very specific fixed integer size types and 2's complement. As they are successfully, that Darwinian pressure will push on C. My crystal ball says we will see a slow migration to increasing uses of fixed width types in C.

What was the purpose of the design of nonspecific size types like int and short?

It was a good first step to accommodate the wide variety of various integer widths (8,9,12,18,36, etc.) and encodings (2's, 1's, sign/mag). So much coding today uses power-of-2 size integers with 2's complement, that one may not realize that many other arrangements existed beforehand. See previous answer also.

这篇关于uint32_t的VS INT作为日常编程公约的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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