alignas specifier vs __attribute __(aligned),c ++ 11 [英] alignas specifier vs __attribute__(aligned), c++11

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

问题描述

我目前正在使用C ++ 11开发一个操作系统内核,我遇到了一个问题,我似乎找不到自己的答案。

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说明符,在Clang ++这是没有问题,因为它高兴地接受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 __属性__(aligned)之间的主要区别显然都是确保与特定值,但是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?

为什么不能通过const integer to the alignas specifier?

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(std :: 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).

由大于
alignof(std :: max_align_t)的对齐表示。它是实现定义的是否支持任何扩展的
对齐和支持它们的上下文(7.1.6)。具有扩展对齐要求的类型
是过对齐类型。

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.

):


如果常量表达式计算为扩展对齐方式,而实现
不支持

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 specifier vs __attribute __(aligned),c ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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