c++ - C++中的$符号

标签 c++ multithreading syntax locking

我从开源库中读取了以下代码。令我困惑的是美元符号的用法。任何人都可以澄清代码中 $ 的含义。非常感谢您的帮助!

   __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;

最佳答案

有一个 gcc 开关,-fdollars-in-identifiers,它明确允许在标识符中使用 $。

也许他们启用它并使用 $ 作为与普通名称极不可能发生冲突的东西。

-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.

参见 the gcc documentation .希望链接保持良好。

关于c++ - C++中的$符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14595300/

相关文章:

c++ - 命名空间语法 "::Foo"

winapi - 如何在win32中使用线程功能显示进度条?

c - 使 int foo(int bar[][N]) 与 int ** baz 一起工作

c++ - 命名(通用)线程安全数据结构?

mysql - 间隔1分钟更新日期和时间序列MYSQL

Scala 类构造函数默认参数,表达式使用以前的成员

C++ - 类中的私有(private)变量

c++ - 在 constexpr GLenum 数组中存储 OpenGL 颜色附件

c++ - 为什么 CreateSemaphore 工作时 OpenSemaphore 在 64 位 Windows 7 中总是返回零?

java - 批处理文件执行可以单步执行序列而不完成 java 进程吗?