问题涉及到调整 [英] Question related to alignment

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

问题描述

这是个很好的做法组相同类型的所有变量在一起,同时在本地范围内的函数内声明?如果是,为什么?它解决内存对齐问题?

Is it a good practice to group all the variables of same type together while declaring in local scope within a function? If yes, why? Does it solve memory alignment issues?

推荐答案

我觉得它在VAX C编译器我在20年前使用要紧,但不与任何现代编译器。它的的安全的假设,局部变量会在任何特定的顺序,肯定不会安全的假设,他们将在命令你声明它们。我曾经的绝对的看到MSVC的编译器重新排序。

I think it mattered with the VAX C compiler I used 20 years ago, but not with any modern compiler. It is not safe to assume that local variables will be in any particular order, certainly not safe to assume they will be in the order you declared them. I have definitely seen the MSVC compiler reorder them.

同类型的分组变量的确实的帮助时,他们是一个结构的领域,因为一个结构域的顺序是保证匹配声明的顺序。

Grouping variables of the same type does help when they are fields of a struct, because the ordering of fields of a struct is guaranteed to match the order of declaration.

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

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