静态声明遵循非静态

时间:2012-09-25 12:54:18

标签: c gcc avr

在我的avrstudio4项目中,我遇到了这个错误:

../Indication.c:95:15: error: static declaration of 'menu_boot' follows non-static declaration
在main.c 中输入 #include“indication.h”

indication.h indication.c 的头文件,函数在其中定义如下:

unsigned char menu_boot(unsigned char index, unsigned char *menu1) 
__attribute__((section(".core")));

indication.c 我有

#include "indication.h"
...
unsigned char menu_boot(unsigned char index, unsigned char *menu1)

我该怎么办?

1 个答案:

答案 0 :(得分:1)

取决于面值,错误消息表示在文件../Indication.c的第95行(可能与您讨论的名为indication.c的文件相同或不同),有一个menu_boot的静态声明,例如:

static unsigned char menu_boot(unsigned char index, unsigned char *menu1);

或其静态定义,例如:

static unsigned char menu_boot(unsigned char index, unsigned char *menu1)
{
    ...
}

请考虑文件xx.c中的以下代码:

extern unsigned char function(int abc);

static unsigned char function(int abc);

static unsigned char function(int abc)
{
    return abc & 0xFF;
}

使用GCC 4.1.2(在RHEL 5上)编译时,编译器会说:

$ gcc -c xx.c
xx.c:3: error: static declaration of ‘function’ follows non-static declaration
xx.c:1: error: previous declaration of ‘function’ was here
$

如果我注释掉第三行,那么编译器会说:

$ gcc -c xx.c
xx.c:6: error: static declaration of ‘function’ follows non-static declaration
xx.c:1: error: previous declaration of ‘function’ was here
$

消息是相同的,但包含有关上一个声明所在位置的信息。在这种情况下,它在同一个源文件中;如果声明位于翻译单元中包含的不同源文件(通常是标题)中,那么它将标识该其他文件。