【问题标题】:static declaration follows non-static静态声明遵循非静态
【发布时间】:2016-02-17 09:25:53
【问题描述】:

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

../Indication.c:95:15: error: static declaration of 'menu_boot' follows non-static declaration

ma​​in.c 我输入 #include "indication.h"

indication.hindication.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)

我该怎么办?

【问题讨论】:

  • 您的 .c 文件中的内容是否应该在签名后也没有 __attribute__((section(".core")))
  • 这可能对你有帮助stackoverflow.com/questions/3148244/…
  • 您是否在Indication.cindication.c 引用同一文件的系统上?你的编译错误在Indication.c,所以除非文件系统不区分大小写,否则你正在查看错误的文件。 (Mac 和 Windows 通常不区分大小写。)您的 GCC 版本是否没有告诉您之前的声明在哪里?
  • @rjayavrp:x-ref 的问题当然涵盖了同样的问题。不过,答案并没有详细解释正在发生的事情。

标签: c gcc avr


【解决方案1】:

从表面上看,错误消息意味着在文件../Indication.c的第95行(可能与您讨论的名为indication.c的文件相同也可能不同),有一个@的静态声明987654323@如:

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
$

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多