的sizeof ... [英] sizeof...

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

问题描述

问候!!

目前我正在从K& R学习C.我有DOS& Linux在我的

系统中。当我使用sizeof()关键字来计算整数的大小时,它会在DOS和Linux中显示不同的结果。在DOS中它显示整数

占用2个字节,但在Linux中它显示4个字节。是sizeof运算符

真的显示机器数据或寄存器大小?

请帮助

me !!

Greetings!!
Currently i am learning C from K&R.I have DOS & Linux in my
system.When i used sizeof() keyword to compute the size of integer , it
shows different results in DOS and Linux.In DOS it shows integer
occupies 2 bytes , but in Linux it shows 4 bytes.Is sizeof operator
"really" shows the machine data or register size ?
Please help
me!!

推荐答案

th ************ @ hotmail.com 写道:
th************@hotmail.com wrote:
问候!!
目前我正在学习来自K& RI的C有DOS& Linux在我的
系统中。当我使用sizeof()关键字来计算整数的大小时,它在DOS和Linux中显示不同的结果。在DOS中它显示整数
占用2个字节,但是在Linux中它显示4个字节。是sizeof运算符
真的显示机器数据或寄存器大小?
请帮助
我!!
Greetings!!
Currently i am learning C from K&R.I have DOS & Linux in my
system.When i used sizeof() keyword to compute the size of integer , it
shows different results in DOS and Linux.In DOS it shows integer
occupies 2 bytes , but in Linux it shows 4 bytes.Is sizeof operator
"really" shows the machine data or register size ?
Please help
me!!




这取决于编译器 - 32位编译器(GCC等)返回4个字节每个

整数和旧的16位编译器(PacifiC,Turbo C)返回2个字节/

整数。


- -

----------------------------------------- ----
www.cepa.one.pl
FreeBSD r0xi qrde; - ]



It depends on compiler - 32 bit compilers (GCC etc) returns 4 bytes per
integer and old 16 bit compilers (PacifiC, Turbo C) returns 2 bytes per
integer.

--
---------------------------------------------
www.cepa.one.pl
FreeBSD r0xi qrde ;-]


2005年5月29日07:02:12 -0700," th ********* ***@hotmail.com"

< th ************ @ hotmail.com>写道:
On 29 May 2005 07:02:12 -0700, "th************@hotmail.com"
<th************@hotmail.com> wrote:
问候!!
目前我正在从K& R学习C.我有DOS& Linux在我的
系统中。当我使用sizeof()关键字来计算整数的大小时,它在DOS和Linux中显示不同的结果。在DOS中它显示整数
占用2个字节,但是在Linux中它显示4个字节。是sizeof运算符
真的显示机器数据或寄存器大小?
请帮助
我!!
Greetings!!
Currently i am learning C from K&R.I have DOS & Linux in my
system.When i used sizeof() keyword to compute the size of integer , it
shows different results in DOS and Linux.In DOS it shows integer
occupies 2 bytes , but in Linux it shows 4 bytes.Is sizeof operator
"really" shows the machine data or register size ?
Please help
me!!




DOS用于旧的8086/88处理器。这些是16位

处理器(因此:int是2个字节)。在较新的机器上,CPU在运行DOS(实模式或V86

模式)时以兼容模式运行
。这并不意味着处理器突然是一个16位的处理器,它只是一个处理器。


因此,在这种情况下,sizeof不会不显示寄存器大小(32位/ b $ b位)。只有默认的操作数大小,在这个

兼容模式下是16位。



DOS was made for the old 8086/88 processors. These were 16 bit
processors (thus : int being 2 bytes). On newer machines, the CPU runs
in a compatibility mode when running DOS (either real mode or V86
mode). It doesn''t mean that the processor is suddenly a 16 bit
processor, it only acts like one.

So, in this case sizeof doesn''t show the register size (which is 32
bits). Only the default operand size, which is 16 bits in this
compatibility mode.


th ************ @ hotmail.com 写于29/05/05:
th************@hotmail.com wrote on 29/05/05 :
目前我正在学习来自K& RI的C有DOS& Linux在我的
系统中。当我使用sizeof()关键字来计算整数的大小时,它在DOS和Linux中显示不同的结果。在DOS中它显示整数
占用2个字节,但是在Linux中它显示4个字节。是sizeof运算符
真的显示机器数据或寄存器大小?
Currently i am learning C from K&R.I have DOS & Linux in my
system.When i used sizeof() keyword to compute the size of integer , it
shows different results in DOS and Linux.In DOS it shows integer
occupies 2 bytes , but in Linux it shows 4 bytes.Is sizeof operator
"really" shows the machine data or register size ?



sizeof返回常量或对象占用的字节数。


是的,int可以在x86实模式(PC / Ms-Dos)上使用2个字符,在
x86保护/扩展模式(PC / Win32,Linux)上使用4个字符。它还可以在DSP TMS320C54(Texas Instrument)上使用1个字符
,其中char和int都是

16位宽度。

-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

C -library: http://www.dinkumware.com/refxc.html


" Mal nommer les choses c''est ajouter du malheur au

monde。" - Albert Camus。



sizeof returns the number of byte occupied by a constant or an object.

Yes, an int can use 2 char on x86 real mode (PC/Ms-Dos) and 4 char on
x86 protected/extended mode (PC/Win32, Linux). It could also use 1 char
on a DSP TMS320C54 (Texas Instrument) where a char and and int are both
16-bit width.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Mal nommer les choses c''est ajouter du malheur au
monde." -- Albert Camus.


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

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