双括号"[[foo()]] type name;"的含义C ++中的语法? [英] Meaning of double bracket "[[foo()]] type name;" syntax in c++?

查看:86
本文介绍了双括号"[[foo()]] type name;"的含义C ++中的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文章中,避免虚假共享,显示以下代码以进行对齐:

In this article about avoiding False Sharing, the following code snipped for alignment is presented:

// C++ (using C++0x alignment syntax)
template<typename T>
struct cache_line_storage {
   [[ align(CACHE_LINE_SIZE) ]] T data;
   char pad[ CACHE_LINE_SIZE > sizeof(T)
        ? CACHE_LINE_SIZE - sizeof(T)
        : 1 ];
};

第4行是什么意思?我以前从未见过这种双括号语法.

What is the meaning of line 4? I've never seen this double bracket syntax before.

推荐答案

属性说明符语法.它是作为一种统一的语法引入的,以访问以前是编译器特定的扩展(现在已标准化).

That is the attribute specifier syntax. It was introduced as a unified syntax to access what were formerly compiler-specific extensions (now some are standardized).

在这种情况下,代码告诉编译器将数据 CACHE_LINE_SIZE 字节对齐.

In this case the code is telling the compiler to align data to CACHE_LINE_SIZE bytes.

这篇关于双括号"[[foo()]] type name;"的含义C ++中的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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