问题描述
我正在编写针对基于 SAME51 的 Atmel/microchip 处理器的 c 代码。我正在使用 microchip 的 MPLABX 来编译和运行代码。
我有多个 .c 文件中多次包含的头文件。当我将 triac.h
包含到 keypad.c
中时遇到错误:
In file included from ../src/keypad.c:23:0:
../src/triac.h:39:54: error: expected ')' before 'uintptr_t'
typedef void (*p_triac_isr_reg)(TC_COMPARE_CALLBACK,uintptr_t);
^~~~~~~~~
../src/triac.h:78:5: error: unkNown type name 'p_triac_isr_reg'
p_triac_isr_reg isr_register;
双向可控硅.h:
#ifndef TRIAC_H
#define TRIAC_H
#include <stdint.h>
#include <stdbool.h>
#include "./config/Test/peripheral/eic/plib_eic.h"
#include "./config/Test/peripheral/tc/plib_tc_common.h" // << Needed to add this
typedef void (*p_triac_funct)();
typedef void (*p_triac_isr_reg)(TC_COMPARE_CALLBACK,uintptr_t);
typedef struct triac_t
{
bool is_enabled;
uint16_t current_setting;
uint16_t min_period;
uint16_t max_period;
p_triac_funct isr;
p_triac_isr_reg isr_register;
bool (*set_output)(uint16_t);
uint16_t (*get_output)();
} triac_t;
extern triac_t *p_ac_triac;
extern frequency_t lineFrequency; // Line Frequency (FREQ_50HZ or FREQ_60HZ)
#endif // TRIAC_H
我在 triac.h
、triac.c
和其他几个文件中包含了 keypad.c
。如果我从 #include "triac.h"
中删除 keypad.c
一切编译正常没有任何错误。我在这一点上很卡。
更新
我需要将 #include "./config/Test/peripheral/tc/plib_tc_common.h"
添加到我的 triac.h
谢谢@tstanisl!我以为它包含在 "./config/Test/peripheral/eic/plib_eic.h"
中,但我错了。我很抱歉没有提供所有必要的部分,但代码依赖于 MPLAB Harmony 框架的使用。
plib_tc_common.h
typedef void (*TC_COMPARE_CALLBACK) (TC_COMPARE_STATUS status,uintptr_t context);
我被这个错误抛弃了,因为同一个头文件被包含在多个其他 .c
文件中,没有任何错误。其他 .c
文件没有任何定义 #includes
的 TC_COMPARE_CALLBACK
,所以我仍然不确定 为什么 它以前有效。
解决方法
既然已经在评论中确定了错误原因,只剩下这种不明确之处:
我被这个错误抛弃了,因为同一个头文件被包含在多个其他 .c
文件中,没有任何错误。其他 .c
文件没有任何定义 #includes
的 TC_COMPARE_CALLBACK
,所以我仍然不确定 为什么 它以前有效。
这样做的原因肯定是 before 你没有在
之前包含<stdint.h>
typedef void (*p_triac_isr_reg)(TC_COMPARE_CALLBACK,uintptr_t);
(就像在您更新帖子之前的原始问题一样);这样,TC_COMPARE_CALLBACK
和 uintptr_t
只是旧式仍然合法的函数参数列表中的任意参数名称(没有类型)。