gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:24:17 25 4
gpt4 key购买 nike

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

定时器.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com