由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C问题,被64bit iPhone搞晕了
相关主题
一道面试题写一个C语言的编译器大概要多少时间?
问一下可能性,MingW生成的DLL和MSVC生成的DLL两个线程同步fread/fwrite有big/small endian问题吗?
两个class的交叉引用问题请教一个C的问题
另一个Fortran 问题问达人一个shared memory 的问题
【请教】mpicc 和 mpiCC编译问题面试题还是不太清楚怎么回答。尤其是8,我用MSVC试了一下,没有问题啊。
C语言的变量都一定要放在stack上吗?lifeaswater, please answer question in post 5700
how to get division and reminder in one operation?Qt/Windows 开源版本将支持 VS Express
这里的牛人很多,都读过标准吗C array
相关话题的讨论汇总
话题: int话题: iphone话题: long话题: int32话题: 64bit
进入Programming版参与讨论
1 (共1页)
i*****o
发帖数: 1714
1
一直以为int和long不管32还是64都是4个byte,怎么apple说int和long在64位下不一样
大?难道ansi没这方面的规定?
★ 发自iPhone App: ChineseWeb 8.0.1
k**********g
发帖数: 989
2

是被 MSVC 搞昏吧。除了 MSVC 有这样规定(为了 MS 自家代码的向後兼容),没听过
其他编译器有这样的保证。

【在 i*****o 的大作中提到】
: 一直以为int和long不管32还是64都是4个byte,怎么apple说int和long在64位下不一样
: 大?难道ansi没这方面的规定?
: ★ 发自iPhone App: ChineseWeb 8.0.1

m*******n
发帖数: 305
3
char[4] 是否可以保证32位?
g****t
发帖数: 31659
4
这是个compiler问题.

【在 m*******n 的大作中提到】
: char[4] 是否可以保证32位?
t****t
发帖数: 6806
5
actually char[4] is guaranteed to be 4 bytes. however 1byte=8bit is not
guaranteed, although the risk is quite minimal.
for compatibility, try int32_t in , if it exist.

【在 g****t 的大作中提到】
: 这是个compiler问题.
p*****w
发帖数: 429
6
这样可以自己定义吗
?
#ifndef int32
#if sizeof(long)==4
#define int32 long
#endif
#if sizeof(int)==4
#endif

【在 t****t 的大作中提到】
: actually char[4] is guaranteed to be 4 bytes. however 1byte=8bit is not
: guaranteed, although the risk is quite minimal.
: for compatibility, try int32_t in , if it exist.

d****i
发帖数: 4809
7
ANSI C没有规定int和long的字节数,因为在不同的CPU架构和C编译器下,int和long的
字长都不一样,比如一般都认为int是32位,但是在有的16位MCU下,int却是16位。

【在 i*****o 的大作中提到】
: 一直以为int和long不管32还是64都是4个byte,怎么apple说int和long在64位下不一样
: 大?难道ansi没这方面的规定?
: ★ 发自iPhone App: ChineseWeb 8.0.1

d****i
发帖数: 4809
8
所以比较好的方法是,针对不同的处理器,采用头文件types.h来自定义:
#ifdef _ARM_CORTEX
typedef int INT32;
typedef unsigned int UINT32;
typedef short INT16;
......
#endif

【在 i*****o 的大作中提到】
: 一直以为int和long不管32还是64都是4个byte,怎么apple说int和long在64位下不一样
: 大?难道ansi没这方面的规定?
: ★ 发自iPhone App: ChineseWeb 8.0.1

n***e
发帖数: 723
9
不要看见什么就来黑微软,微软这么做是因为AMD64上的int是4位的。
http://wiki.inspircd.org/Type_Sizes#AMD64_Gentoo_Linux_64bit.2C

【在 k**********g 的大作中提到】
:
: 是被 MSVC 搞昏吧。除了 MSVC 有这样规定(为了 MS 自家代码的向後兼容),没听过
: 其他编译器有这样的保证。

v*****u
发帖数: 1796
10
同意. 规定是 long的位数>=int

【在 d****i 的大作中提到】
: ANSI C没有规定int和long的字节数,因为在不同的CPU架构和C编译器下,int和long的
: 字长都不一样,比如一般都认为int是32位,但是在有的16位MCU下,int却是16位。

相关主题
C语言的变量都一定要放在stack上吗?写一个C语言的编译器大概要多少时间?
how to get division and reminder in one operation?fread/fwrite有big/small endian问题吗?
这里的牛人很多,都读过标准吗请教一个C的问题
进入Programming版参与讨论
c*****m
发帖数: 1160
11
我印象谭浩强的书里有说这个:
在 ANSI C里,
short <= int <= long
而且说了具体每个编译器实现都可以不一样,只要实现这个公式就是标准。
k**********g
发帖数: 989
12

(我是软粉。)
This post talks about integer widths from the language / compiler
perspective. This post is strictly unrelated to the design or limitations of
the underlying CPU architecture. In all cases, compiler has the
responsibility of enabling, and if necessary, emulating the integer types of
various widths.
Turbo Pascal supports 32-bit integer types on 16-bit DOS processes and CPUs.
It provides the REAL floating point type, which is 6 bytes (48 bits) and is
strictly emulated in software.

【在 n***e 的大作中提到】
: 不要看见什么就来黑微软,微软这么做是因为AMD64上的int是4位的。
: http://wiki.inspircd.org/Type_Sizes#AMD64_Gentoo_Linux_64bit.2C

t****t
发帖数: 6806
13
大多数int都是32位的. 但楼主问的不是这个, 他问的是为什么long居然是64位的. 我们
说, 除了MSVC, 其它64位编译器几乎都规定long是64位的. 你贴的link恰好说明了这一
点.
另外, "AMD64上的int是4位(4byte?)"这个说法本身不make sense. int的宽度并不由CP
U决定.

【在 n***e 的大作中提到】
: 不要看见什么就来黑微软,微软这么做是因为AMD64上的int是4位的。
: http://wiki.inspircd.org/Type_Sizes#AMD64_Gentoo_Linux_64bit.2C

x****u
发帖数: 44466
14
MS的编译器在AMD64架构和安腾上的字节长也不一样。

我们
CP

【在 t****t 的大作中提到】
: 大多数int都是32位的. 但楼主问的不是这个, 他问的是为什么long居然是64位的. 我们
: 说, 除了MSVC, 其它64位编译器几乎都规定long是64位的. 你贴的link恰好说明了这一
: 点.
: 另外, "AMD64上的int是4位(4byte?)"这个说法本身不make sense. int的宽度并不由CP
: U决定.

c****p
发帖数: 6474
15
实现决定。long>=int即可。
现在多数64位编译器long都是64位。

【在 i*****o 的大作中提到】
: 一直以为int和long不管32还是64都是4个byte,怎么apple说int和long在64位下不一样
: 大?难道ansi没这方面的规定?
: ★ 发自iPhone App: ChineseWeb 8.0.1

n***e
发帖数: 723
16
Huh, you are correct on this. My apologies.

of
of
CPUs.
is

【在 k**********g 的大作中提到】
:
: (我是软粉。)
: This post talks about integer widths from the language / compiler
: perspective. This post is strictly unrelated to the design or limitations of
: the underlying CPU architecture. In all cases, compiler has the
: responsibility of enabling, and if necessary, emulating the integer types of
: various widths.
: Turbo Pascal supports 32-bit integer types on 16-bit DOS processes and CPUs.
: It provides the REAL floating point type, which is 6 bytes (48 bits) and is
: strictly emulated in software.

1 (共1页)
进入Programming版参与讨论
相关主题
C array【请教】mpicc 和 mpiCC编译问题
sscanf problem in MSVC 7C语言的变量都一定要放在stack上吗?
一道c++的考古题how to get division and reminder in one operation?
[合集] 面试题还是不太清楚怎么回答。尤其是8,我用MSVC试了一下,没有这里的牛人很多,都读过标准吗
一道面试题写一个C语言的编译器大概要多少时间?
问一下可能性,MingW生成的DLL和MSVC生成的DLL两个线程同步fread/fwrite有big/small endian问题吗?
两个class的交叉引用问题请教一个C的问题
另一个Fortran 问题问达人一个shared memory 的问题
相关话题的讨论汇总
话题: int话题: iphone话题: long话题: int32话题: 64bit