在64位机器中存储char [英] Storage of char in 64 bit machine

查看:97
本文介绍了在64位机器中存储char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在C文件中有一个简单的definitioin,就像这样。


main()

{

char a;

.......

int k;

}


由于字符是8位,如何将它存储在机器中的64位
机器中。如果它是字对齐的,那么剩下的字节呢。什么

关于char c的检索,它会很贵。是不是很贵或者写的是



Thanx和问候,

Aruna

Hi all,

I have a simple definitioin in a C file something like this.

main()
{
char a;
.......
int k;
}

Since character is 8 bit, how is it stored in the machine in a 64 bit
machine. If it is word aligned, what about the rest of the bytes. What
about the retrievel of the char c, will it be expensive. Is it
expensive w.r.t read or write.

Thanx and Regards,
Aruna

推荐答案

ar ********* *@gmail.com 写道:
ar**********@gmail.com wrote:

大家好,


我在C中有一个简单的definitioin提交类似这样的文件。


main()

{

char a;

.. .....

int k;

}


由于字符是8位,它是如何存储在机器中的在64位

机器上。
Hi all,

I have a simple definitioin in a C file something like this.

main()
{
char a;
.......
int k;
}

Since character is 8 bit, how is it stored in the machine in a 64 bit
machine.



这取决于编译器,它取决于你所说的64位

机器。 />

That''s up to the compiler, and it depends what you mean by "a 64 bit
machine".


如果它是字对齐的,那么剩下的字节呢。
If it is word aligned, what about the rest of the bytes.



剩下的几个字节怎么样?

What about the rest of what bytes?


char c的检索怎么样,将它很贵。
What about the retrievel of the char c, will it be expensive.



这取决于编译器。我不会/期望/它是昂贵的。

`c`可能存储在寄存器中,例如[1]。

That depends on the compiler. I wouldn''t /expect/ it to be expensive.
`c` might well be stored in a register, for example [1].


读取或写入是否昂贵?
Is it expensive w.r.t read or write.



这取决于。


您有问题需要解释吗?

(忽略你的``s,编译器可以安排上面的`main`实现没有局部变量......)b / b


-

Chris" seeker" Dollin

伸出隐藏在网络中的镜子。 - 文艺复兴,/奔跑/

That depends.

Have you a problem for which this would be an explanation?

(Ignoring your `...`s, the compiler could arrange that `main` above
is implemented with no local variables at all ...)

--
Chris "seeker" Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/



ar ********** @ gmail.com 写道:

大家好,


我在C文件中有一个简单的definitioin,就像这样。


main()

{

char a;

.......

int k;

}


因为字符是8位,
Hi all,

I have a simple definitioin in a C file something like this.

main()
{
char a;
.......
int k;
}

Since character is 8 bit,



实际上,一个字符不是8位。我正在简化,但

字符保证是/至少/ 8位宽,并且允许

尽可能宽。对于我们(或者你)所知道的所有人,你的平台上的字符可能是44美元宽的字符串。

Actually, a character isn''t 8 bit. I''m simplifying a bit, but a
character is guaranteed to be /at least/ 8 bits wide, and is permitted
to be as wide as necessary. For all we (or you) know, a char might be
64bits wide on your platform.


它是如何存储在机器中的在64位

机器上。如果它是字对齐的,那么剩下的字节呢。什么

关于char c的检索,它会很贵。是不是昂贵的w.r.t读或写。
how is it stored in the machine in a 64 bit
machine. If it is word aligned, what about the rest of the bytes. What
about the retrievel of the char c, will it be expensive. Is it
expensive w.r.t read or write.



存储和对齐是编译器和

执行平台的关注点。它/可能/可能是这个编译器像你一样怀疑,并使用64位中的8位存储一个char实体,留下

剩余的位未使用且无法使用。


或者,编译器/可以/重新组织你的分配(在任何一个级别的b $ b $),这样所有的小实体都被组合在一起

存储,允许其他字符值占用松弛值。来自

的空间你的char a;分配。


这完全取决于编译器的实现; AFAICR,

C标准在这方面不需要任何特定的行为。如果

编译器的代码组织和优化对于你来说是个问题,那么你要么必须切换编译器或者将代码更改为实时
更符合编译器对你的限制。

Storage and alignment are the concerns of the compiler and the
"execution platform". It /could/ be that this compiler does as you
suspect, and uses 8 bits out of 64 to store a char entity, leaving the
remaining bits unused and unusable.

Alternatively, the compiler /may/ reorganize your allocations (at any
one level) such that all the small entities are grouped together in
storage, permitting other char values to occupy the "slack" space from
your allocation of "char a;".

This is entirely up to the implementation of the compiler; AFAICR, the
C standard doesn''t require any specific behaviour in this regard. If
the compiler''s code organization and optimization are a problem for
you, you''ll either have to switch compilers or change your code to live
more optimally within the restrictions that the compiler places on you.


Thanx和问候,

Aruna
Thanx and Regards,
Aruna



不客气

-

Lew Pitcher

You''re welcome
--
Lew Pitcher

< br>

在文章< 11 ********************** @ b28g2000cwb.googlegroups .com> ;,

Lew Pitcher< lp ****** @ sympatico.cawrote:
In article <11**********************@b28g2000cwb.googlegroups .com>,
Lew Pitcher <lp******@sympatico.cawrote:

>或者,编译器/可以/重新组织你的分配(在任何地方
一级)使得所有小实体在存储器中组合在一起,允许其他字符值占据松弛状态。您分配char a;的空间。
>Alternatively, the compiler /may/ reorganize your allocations (at any
one level) such that all the small entities are grouped together in
storage, permitting other char values to occupy the "slack" space from
your allocation of "char a;".


>这完全取决于编译器的实现; AFAICR,
C标准在这方面不需要任何特定的行为。
>This is entirely up to the implementation of the compiler; AFAICR, the
C standard doesn''t require any specific behaviour in this regard.



我不确定你的意思是在任何一个级别。


注意编译器是不允许重新排序结构中的字段,

只是在字段之间放置填充。 (我倾向于认为

任何一个结构的字段都在同一个级别,提供

它们不是聚合类型。)

-

编程就是在你忙于制定其他计划的时候发生的事情。

I''m not sure what you mean by "at any one level".

Note that compilers are not permitted to reorder fields in a struct,
only to put padding between the fields. (I would tend to think
that fields of any one struct are all at the same "level", provided
they are not aggregate types.)
--
Programming is what happens while you''re busy making other plans.


这篇关于在64位机器中存储char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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