C++

__attribute__((unused)) 的含义

2018-05-02  本文已影响910人  louyang

在C程序中,如果定义了一个静态函数,而没有去使用,编译时会有一个告警:

#include <stdio.h>

int main(void)
{
    printf("main\n");
}

static void a(void)
{
    printf("a\n");
}
$ gcc a.c -Wall
a.c:8:13: warning: 'a' defined but not used [-Wunused-function]
 static void a(void)
             ^

而使用attribute((unused))可以告诉编译器忽略此告警:

#include <stdio.h>

int main(void)
{
    printf("main\n");
}

__attribute__((unused)) static void a(void)
{
    printf("a\n");
}
$ gcc a.c -Wall
$
上一篇下一篇

猜你喜欢

热点阅读