"互锁增量":在 Visual C++ 2008 中找不到标识符错误

'InterlockedIncrement': identifier not found error in visual c++ 2008

本文关键字:2008 找不到 错误 标识符 C++ Visual      更新时间:2023-10-16

你好,我已经编译了下面指定的代码

long (*interlocked_increment) (volatile long *);
long InterlockedIncrement(volatile long & value) const {
        return interlocked_increment(&value);
      }
static long m_interlocked_increment(volatile long * pv) {
#ifdef WIN32
  return InterlockedIncrement(pv); 
#elif defined(HAS_SYNC_FUNCTIONS)
  return __sync_fetch_and_add(pv, 1L);
#else
  return ++(*pv);
#endif
}

在g++编译器中可以正常工作。但是,当我在visual c++ 2008中尝试相同时,它显示了以下指定的错误。我怎样才能解决这个问题呢?

错误5错误C3861: 'InterlockedIncrement':标识符未找到

InterlockedIncrement()函数使用volatile long &,而您传递给它的是volatile long *,因此编译器找不到相应的函数签名