defined but not used警告屏蔽

编程过程中会遇到一些调试级别的函数,程序运行中往往用不到,但是删除该函数又会影响调试

warning: ‘void test()’ defined but not used [-Wunused-function]

对于这种错误的解决方案是在函数声明的时候添加__attribute__((unused))明确告诉编译器该函数暂时不使用。

示例代码

static void test() __attribute__((unused));

static void test()
{
    printf("hello world");
}

 

posted on 2025-10-30 14:47  寒魔影  阅读(5)  评论(0)    收藏  举报

导航