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.
Writing two brackets next to each other means the brackets need to be multiplied together. For example, ( y + 2 ) ( y + 3 ) means ( y + 2 ) × ( y + 3 ) . When expanding double brackets, every term in the first bracket has to be multiplied by every term in the second bracket.
It's just a notation for where a variable value should be substituted. They could have picked anything, but double brackets are both reasonably concise yet very unlikely to be found in HTML code otherwise.
Square brackets are used to index (access) elements in arrays and also Strings. Specifically lost[i] will evaluate to the ith item in the array named lost.
Curly braces (also referred to as just "braces" or as "curly brackets") are a major part of the C++ programming language. They are used in several different constructs, outlined below, and this can sometimes be confusing for beginners.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With