问题
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 ];
};
What is the meaning of line 4? I've never seen this double bracket syntax before.
回答1:
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).
In this case the code is telling the compiler to align data
to CACHE_LINE_SIZE
bytes.
来源:https://stackoverflow.com/questions/40451840/meaning-of-double-bracket-foo-type-name-syntax-in-c