对准 [英] Alignment

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

问题描述

如何声明保证最严格的变量

对齐?


-

辩护律师是锤击原告:

你声称,他嘲笑道,我的客户手里拿着一个破瓶子来了,他手里拿着
。但是,你手上有什么东西不是真的吗?

是的,是的,该男子承认,他的妻子。非常迷人,当然,

但在战斗中并不太好。

解决方案



< fi ****** @ invalid.comwrote in message

news:sl ******************** @ nospam.invalid ...


如何声明保证最严格的变量

alignment?


在实践中,调整为双倍。

例如


union alignedint

{

双假人;

int x;

}


x现在将有双重对齐。 />

在严格正确的条款中,使用编译器编译指示来实现你想要的。

double并不保证是最严格对齐的类型而且没有

用于查找它的便携式机械装置。


-

免费游戏和编程好吃的东西。
h ttp://www.personal.leeds.ac.uk/~bgy1mm


fi ****** @ invalid.com 写道:


如何声明保证最严格的变量

对齐?



假设任何对象类型都可以包含在结构或联合中,并且

所有结构和联合类型都具有相同的对齐要求,任何

结构或工会类型都可以。


但是,你为什么需要这个呢?标准C中你很少有b $ b可以知道非动态对象的对齐。即使你有

a结构包含一个包含四个字符的数组,这个字符已正确对齐

表示int,而sizeof(int)== 4在你的平台上,你'仍然不允许

访问这个结构,就像它是一个int。


Harald van D?3k写道:
< blockquote class =post_quotes> fi******@invalid.com 写道:


>如何声明一个保证最严格的变量
对齐?



鉴于任何对象类型都可以包含在结构或联合中,并且

所有结构和联合类型都具有相同的对齐要求,任何

结构或联合类型都可以。



对不起,这当然是不正确的。我在考虑指向

结构。下面的内容仍然是正确的,尽管你需要采用另一种方式

使结构正确对齐以使其相关。


但是,你为什么需要这个?标准C中你很少有b $ b可以知道非动态对象的对齐。即使你的
有一个包含四个字符数组的结构,这对于一个int正确对齐,并且你的平台上的sizeof(int)== 4,你'仍然没有

允许访问这个结构,就像它是一个int。


How to declare a variable guaranteed to have the strictest possible
alignment?

--
The defense attorney was hammering away at the plaintiff:
"You claim," he jeered, "that my client came at you with a broken bottle
in his hand. But is it not true, that you had something in YOUR hand?"
"Yes," the man admitted, "his wife. Very charming, of course,
but not much good in a fight."

解决方案


<fi******@invalid.comwrote in message
news:sl********************@nospam.invalid...

How to declare a variable guaranteed to have the strictest possible
alignment?

In practise, align to a double.
eg

union alignedint
{
double dummy;
int x;
}

x will now have double alignement.

In strictly correct terms, use compiler pragmas to achieve what you want.
double isn''t guaranteed to be the most strictly aligned type and there is no
portable mechnaism for finding it.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


fi******@invalid.com wrote:

How to declare a variable guaranteed to have the strictest possible
alignment?

Given that any object type can be contained in a structure or a union, and
all structure and union types have the same alignment requirements, any
structure or union type will do.

However, why do you need this? There''s very little in standard C that you
can do with knowledge of alignment of non-dynamic objects. Even if you have
a structure containing an array of four chars, which is properly aligned
for an int, and sizeof(int)==4 on your platform, you''re still not allowed
to access this structure as were it an int.


Harald van D?3k wrote:

fi******@invalid.com wrote:

>How to declare a variable guaranteed to have the strictest possible
alignment?


Given that any object type can be contained in a structure or a union, and
all structure and union types have the same alignment requirements, any
structure or union type will do.

Sorry, this is of course incorrect. I was thinking of pointers to
structures. The below is still true, though you''d need to have another way
of making the structure properly aligned for it to be relevant.

However, why do you need this? There''s very little in standard C that you
can do with knowledge of alignment of non-dynamic objects. Even if you
have a structure containing an array of four chars, which is properly
aligned for an int, and sizeof(int)==4 on your platform, you''re still not
allowed to access this structure as were it an int.


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

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