c - C编程报错后报错信息中的 "label"是什么?

标签 c pointers compiler-errors compilation label

测试.c

#include <stdio.h>
int main(void)
{
    int a = 13; 
    const int **pp = &&a;
    return 0;
}

看上面的代码。

我知道这是不对的。

但是,我的问题是关于我不理解的错误消息

我认为错误消息会包含诸如“需要左值一元操作数”之类的内容。

cc -std=c11 test.c 之后,我得到了这个:

test.c: In function ‘main’:
test.c:7:2: error: label ‘a’ used but not defined
  const int **pp = &&a;

我认为a 应该称为变量标识符,它已经通过int a = 13;定义了;

C语言编译出错后报错信息中的label是什么?

最佳答案

您偶然发现了一个名为 Labels As Values 的非标准 GCC 功能.

将您的代码更改为以下内容,看看会发生什么。

#include <stdio.h>
int main(void) 
{
    int a = 13; 
    void *pp = &&a;
    goto *pp;
    return 0;
a:
    printf("ooooops\n");
    return 0;
}

它基本上是一种使用 goto 标签作为值的方法,在某种意义上,您可以将标签分配给 void * 指针,然后在 中使用该指针code>goto 语句。

这不是标准 C,以确保您不使用任何非标准功能集 -std-std=c99 或任何您的标准我想用。

关于c - C编程报错后报错信息中的 "label"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52694553/

相关文章:

c - 如何使用 LKM Hook 中断门

使用 MSI 连接到 Azure Vault

c - linux下的malloc,隐式限制

c - 调用 C_F_POINTER 时 Fortran 指针和 Fortran 可分配的区别

c++ - 当 B 类是 C++ 中 A 类的成员时,我访问 B 类中 A 类的公共(public)成员的正确方法是什么?

arrays - 如何在CUDA Fortran中分配共享内存阵列?

c - 编译 Hello World 时未找到“stdio.h”文件

c - GSL 中的错误 - 根查找

c++ - 从 int 到 c 字符串 (const char*) 的转换失败

compiler-errors - CGAL 编译器错误 : undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'