C、#if指令和编译错误: operator '/' has no right operand

标签 c if-statement preprocessor

我遇到了一个我不明白的错误,主要是因为 if 引用了代码的注释部分

基本上我有这样的东西:

#ifndef nH
    #define nH 2  // number of hermitian matrices
#endif

然后我有一个 #if 指令

#if (nH != 0)
    gsl_matrix_complex* H[nH];       // hermitian operators
    gsl_vector* evalH[nH];           // eigenvalues of H
#endif

如果我尝试编译,则会收到以下错误:

error: operator '/' has no right operand
     #define nH 2    // number of hermitian matrices

我通过简单地将注释放在 #define 上方来解决这个问题,如下所示:

// number of hermitian matrices
#ifndef nH
    #define nH 2
#endif

此外,如果取消 #if 指令,则不会发生该错误。 不过,我还是不明白这个问题,我想知道到底出了什么问题

谢谢

编辑: 所以,现在我尝试复制它并且它可以完美编译。我不知道,我所能做的就是发布我收到的错误的屏幕截图。正如你所看到的,两者之间没有空格/ error

最佳答案

确保您使用至少设置为 C99 的语言进行预处理。

如果您进行预处理:

#ifndef nH
    #define nH 2  // number of hermitian matrices
#endif
#if (nH != 0)
#endif

gcc-4.8 -std=c89 -E pp.c 

你会得到pp.c:2:20: error: operator '/' has no right operand

但如果您将语言设置为 c99 或更新版本,则不应收到此错误消息(以 gnu89 开头的 gnu* 变体也可以工作)

关于C、#if指令和编译错误: operator '/' has no right operand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42889718/

相关文章:

MySQL If (SELECT count (*) 返回 #1064 错误

c++ - 预处理器和编译器之间的界限到底在哪里?

java - Scala、Maven 和预处理器

c - 来自gcc : braces around scalar initializer, how to fix?的警告

c - fork 工作起来很奇怪

python - 定义一个包含不等式的函数

if-statement - 基于现有类的 Sass 'if' 语句

compilation - 如何使用 nagfor 列出预定义的预处理器变量

c++ - 来自捕获的 PCM 样本数据的 WAV 文件

c - 用 C 语言编程 Arduino,中断 vector 会起作用吗?