Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$ symbol in c++

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;
like image 802
James Avatar asked Jan 30 '13 01:01

James


2 Answers

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.

like image 58
doug65536 Avatar answered Sep 21 '22 06:09

doug65536


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.

like image 38
Lightness Races in Orbit Avatar answered Sep 22 '22 06:09

Lightness Races in Orbit