由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - golang 的int 要怎么用?
相关主题
How to read binary(data) file generated by Fortran in C/C++ (转载)C array
[转载] Mac C++ program questionA C++ compiler related interview question
C puzzle 一日一题贡献一下:本版上搜集的 Google 面试题 (转载)
请教C++里面这个表达一个哈希表问题
为什么大家不喜欢golang的switch?structure to integer
请教一个排序的问题。看一道面试题
什么时候写程序要注意这个问题?a careercup question
A question about class sizeC++ Q 108: swap
相关话题的讨论汇总
话题: int话题: golang话题: bit话题: int32话题: 64
进入Programming版参与讨论
1 (共1页)
n******7
发帖数: 12463
1
golang的int是个alias
32bit机器上是int32
64bit机器上是int64
这不是个问题吗?
比如我只想用int32,用了int在64bit机器上内存都double了?
golang的tutorial说
“The int, uint, and uintptr types are usually 32 bits wide on 32-bit
systems and 64 bits wide on 64-bit systems. When you need an integer value
you should use int unless you have a specific reason to use a sized or
unsigned integer type. ”
我试过坚持用int32,结果老是得转换类型,后来放弃了
n******7
发帖数: 12463
2
关于C/C++的int,找到一个讨论:
就是说不同size的 int确实confusing?
https://stackoverflow.com/a/2331768
Yes, it depends on both processors (more specifically, ISA, instruction set
architecture, e.g., x86 and x86-64) and compilers including programming
model. For example, in 16-bit machines, sizeof (int) was 2 bytes. 32-bit
machines have 4 bytes for int. It has been considered int was the native
size of a processor, i.e., the size of register. However, 32-bit computers
were so popular, and huge number of software has been written for 32-bit
programming model. So, it would be very confusing if 64-bit computer would
have 8 bytes for int. Both Linux and Windows remain 4 bytes for int. But,
they differ in the size of long.
Please take a look at the 64-bit programming model like LP64 for most *nix
and LLP64 for Windows:
http://www.unix.org/version2/whatsnew/lp64_wp.html
http://en.wikipedia.org/wiki/64-bit#64-bit_data_models
Such differences are actually quite embarrassing when you write code that
should work both on Window and Linux. So, I'm always using int32_t or int64_
t, rather than long, via stdint.h.
1 (共1页)
进入Programming版参与讨论
相关主题
python question, easy one为什么大家不喜欢golang的switch?
A tech question (转载)请教一个排序的问题。
An interesting C++ compile error什么时候写程序要注意这个问题?
谁来解释一下这个是compiler问题吗?A question about class size
How to read binary(data) file generated by Fortran in C/C++ (转载)C array
[转载] Mac C++ program questionA C++ compiler related interview question
C puzzle 一日一题贡献一下:本版上搜集的 Google 面试题 (转载)
请教C++里面这个表达一个哈希表问题
相关话题的讨论汇总
话题: int话题: golang话题: bit话题: int32话题: 64