【问题标题】:GCC function call errorGCC函数调用错误
【发布时间】:2013-01-16 21:48:12
【问题描述】:

我有以下 C 代码:

#ifdef _MODE_DEBUG
void program_exit(void){
#else
void program_exit(const unsigned char* fileName, unsigned int lineNumber){
    printf("The program was called to terminate early from file \"%s\" line %u", fileName, lineNumber);
#endif
//We have to call cleanup() wherever possible.
arguments_cleanup(void);

exit(1);
}

在代码的预编译版本中应该只动态提供一个函数,取决于是否定义了_MODE_DEBUG。但是,GCC 抱怨它在调用 arguments_cleanup 之前需要各种标记。为什么 GCC 不承认这是一个有效的函数,或者为什么这是无效的?

【问题讨论】:

  • 你如何调用这个函数,究竟是什么?
  • 每当发生错误时我都会调用它,函数原型以类似的方式定义。我会使用 EXIT() 调用它,宏会更改为任何必要的内容(取决于 _MODE_DEBUG)

标签: c gcc c-preprocessor


【解决方案1】:
arguments_cleanup(void);

不是调用函数的正确方式,应该是

arguments_cleanup();

编译器试图解释

arguments_cleanup(void);

作为声明。

【讨论】:

  • 或者它只是将其视为语法错误,它是(因为 C99 删除了隐式 int)。
  • hmmm...所以 void 应该只在原型中使用?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多