I read the following code from an open source library. What confuses me is the usage of dollar sign. Can anyone please clarify the meaning of $ in the code. Your help is greatly appreciated!
__forceinline MutexActive( void ) : $lock(LOCK_IS_FREE) {}
void lock ( void );
__forceinline void unlock( void ) {
__memory_barrier(); // compiler must not schedule loads and stores around this point
$lock = LOCK_IS_FREE;
}
protected:
enum ${ LOCK_IS_FREE = 0, LOCK_IS_TAKEN = 1 };
Atomic $lock;
There is a gcc switch, -fdollars-in-identifiers
which explicitly allows $ in idenfitiers.
Perhaps they enable it and use the $ as something that is highly unlikely to clash with normal names.
-fdollars-in-identifiers
Accept $ in identifiers. You can also explicitly prohibit use of $ with the option -fno-dollars-in-identifiers. (GNU C allows $ by default on most target systems, but there are a few exceptions.) Traditional C allowed the character $ to form part of identifiers. However, ISO C and C++ forbid $ in identifiers.
See the gcc documentation. Hopefully the link stays good.
It is being used as part of an identifer.
[C++11: 2.11/1]
defines an identifier as "an arbitrarily long sequence of letters and digits." It defines "letters and digits" in a grammar given immediately above, which names only numeric digits, lower- and upper-case roman letters, and the underscore character explicitly, but does also allow "other implementation-defined characters", of which this is presumably one.
In this scenario the $
has no special meaning other than as part of an identifier — in this case, the name of a variable. There is no special significance with it being at the start of the variable name.
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