c - 相同类型,全部定义,类型冲突

标签 c gcc

经过几个小时的搜索,我没有找到解决我的问题的方法,我将在下面解释。 现在,这些是我的源文件和头文件

定时器.h:

#ifndef TIMER_H
#define TIMER_H

#include "types.h"

uint64 timer_ticks;

void init_timer(uint32 freq);

void wait(uint64 ticks);

void wait_s(uint64 seconds);

void timer_h(struct regs* r);

#endif TIMER_H

定时器.c

 #include "../headers/timer.h"

void init_timer(uint32 freq){
    timer_ticks=0;
    irq_set_handler(0,timer_h);
}

void wait(uint64 ticks){
    uint64 over_ticks=ticks+timer_ticks;
    while(timer_ticks<over_ticks);
}

void wait_s(uint64 seconds){
    uint64 over_ticks=18*seconds;
    wait(over_ticks);
}

void timer_h(struct regs* r){
    timer_ticks++;
}

正如您所见,所有内容都已正确定义,但我从编译器中收到此错误(我使用 GCC-8.2)

include/src/timer.c:21:6: error: conflicting types for 'timer_h'
 void timer_h(struct regs* r){
      ^~~~~~~
In file included from include/src/timer.c:1:
include/src/../headers/timer.h:14:6: note: previous declaration of 'timer_h' was here
 void timer_h(struct regs* r);
      ^~~~~~~

抱歉我的英语不好,提前致谢。

最佳答案

您需要事先声明struct regs;,否则:

timer.c:21:21: warning: declaration of 'struct regs' will not be visible outside of this function [-Wvisibility]

因此每个 struct regs 都是不同的类型。打开警告,让编译器为您发现此类问题。

关于c - 相同类型,全部定义,类型冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53696341/

相关文章:

c++ - 查找没有定义的方法声明

c - 编译 GCC 交叉编译器时目标 'graphite-clast-to-gimple.o' 的配方失败

c - 想知道什么时候用 C 语言免费打电话

c - 错误行 : 43 compiler: expected identifier or '(' before ' [ ' token

c - 这两种说法是否等价?

c - 我如何向 gcc 指定 C 中的 {} init 不应该编译?

c++ - 在内存中复制字节时,字节顺序是否有影响?

c - 简单计数器在 C 中不起作用

c - 如何通知编译器 `getcontext` 可以多次返回?

c - 在 GCC 中使用 -Wall -Wextra 并出现错误