alignas说明VS __attribute __(排列),C ++ 11 [英] alignas specifier vs __attribute__(aligned), c++11

查看:356
本文介绍了alignas说明VS __attribute __(排列),C ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前是在发展中的C ++ 11 OS内核的过程中,我也遇到一个问题,我似乎无法找到答案,以我自己。

I'm currently in the process of developing an OS kernel in C++11, and I've come across a question, I cannot seem to find the answer to myself.

目前我调整我的页面结构,使用编译器特定的属性(如:gcc的 __属性__(校)),但我想使用C ++ 11 alignas说明,而不是上锵++这是没有问题的,因为它很乐意接受4096定位作为参数传递给alignas,不过G ++不!

Currently I'm aligning my paging structures, using compiler specific attributes (eg. gcc's __attribute__(aligned)), however I'm wanting to use the C++11 alignas specifier instead, on Clang++ this is no issue, as it gladly accepts 4096 alignment as parameter to alignas, however G++ does not!

所以首先,什么是之间的的主要区别alignas说明,与海合会 __属性__(校) ,显然既确保统一到一个特定的值,但是在gcc的alignas说明似乎有128个限度,而属性似乎是无限的,这是为什么?

So first of all, what's the main difference between the alignas specifier, and the gcc __attribute__(aligned), obviously both ensure alignment to a specific value, however the alignas specifier in gcc seems to have a limit of 128, while the attribute seems almost limitless, why is this?

另外,为什么不能在一个传递一个常量整数的alignas符?

Also why can't one pass a const integer to the alignas specifier?

推荐答案

这似乎从GCC的支持状态,对准支撑不完全的 GCC 4.7 ,但它是的 GCC 4.8 alignas 也被列为从4.8的发布页面

It seems from the GCC support status, alignment support is not fully supported in gcc 4.7, but it is for gcc 4.8. alignas is also listed as a newly supported feature from the 4.8 release page.

此外,从对齐支持提案(3.11):

Also, from the alignment support proposal (3.11):

一个基本对准,重新通过取向小于或等于由实现在所有上下文所支持的最大的取向,它等于alignof(标准:: max_align_t)(18.1)

A fundamental alignment is represented by an alignment less than or equal to the greatest alignment supported by the implementation in all contexts, which is equal to alignof(std::max_align_t) (18.1).

这是扩展对齐重新通​​过取向大于psented $ P $   alignof(STD :: max_align_t)。这是实现定义是否有扩展   比对支持和上下文中它们所支持的(7.1.6)。 A型   具有扩展对齐的要求是一个过对准型

An extended alignment is represented by an alignment greater than alignof(std::max_align_t). It is implementation-defined whether any extended alignments are supported and the contexts in which they are supported (7.1.6). A type having an extended alignment requirement is an over-aligned type.

和来自同一文件(7.1.6):

And from the same document (7.1.6):

如果不断前pression计算为一个扩展路线和实施   不支持在声明的背景下,对齐方式,程序illformed

if the constant expression evaluates to an extended alignment and the implementation does not support that alignment in the context of the declaration, the program is illformed

这可能是答案的一部分了。我没有访问此刻的完整的标准,有人应该能证实这一点。

That might be part of the answer too. I don't have access to the full standard at the moment, someone should be able to confirm this.

至于__属性之间的的区别__(校) alignas ,我不认为他们是语义上的不同,但一个是刚而另一个完全由标准定义的编译器扩展

As for the difference between __attribute__(aligned) and alignas, i don't think they are semantically different, but one is just a compiler extension while the other is fully defined by the standard.

要回答你的最后一个问题, alignas 只被定义为:

To answer your last question, alignas is only defined for:

alignas ( constant-expression ) 
alignas ( type-id ) 

这篇关于alignas说明VS __attribute __(排列),C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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