Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 存储大小为';变量';isn';不知道_C_Struct - Fatal编程技术网

C 存储大小为';变量';isn';不知道

C 存储大小为';变量';isn';不知道,c,struct,C,Struct,我有一个关于“a的存储大小未知”的问题。我检查了stackoverflow,找到了一些答案。但是,这些解决方案不起作用,或者我不能很好地使用这些答案 请帮我解决我的问题。 谢谢你的帮助,祝你度过愉快的一天 main.c文件 #include <avr/io.h> #include <PORT.h> int main(void) { // Insert code PORT a; while(1) ; return 0; }

我有一个关于“a的存储大小未知”的问题。我检查了stackoverflow,找到了一些答案。但是,这些解决方案不起作用,或者我不能很好地使用这些答案

请帮我解决我的问题。 谢谢你的帮助,祝你度过愉快的一天

main.c文件

#include <avr/io.h>
#include <PORT.h>

int main(void)
{

    // Insert code
    PORT a;

    while(1)
    ;

    return 0;
}
#包括
#包括
内部主(空)
{
//插入代码
a港;
而(1)
;
返回0;
}
端口.h文件

#ifndef PORT_H_INCLUDED
#define PORT_H_INCLUDED

#include <config.h>

    typedef enum PORT_TYPE{
    // All port in ATmega328P
        PORT_B,
        PORT_C,
        PORT_D
    }PORT_TYPE;

    typedef enum PORT_PIN{
    // All pins in ATmega328P
        PIN_0,
        PIN_1,
        PIN_2,
        PIN_3,
        PIN_4,
        PIN_5,
        PIN_6,
        PIN_7
    }PORT_PIN;

    typedef struct PORT PORT;

    void PORT_init(PORT * const me,
                   void (* setDirectionFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* setStatusFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* enablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* disablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* notifyPinChangeFunction)(PORT * const me, PORT_PIN pinNumber),
                   unsigned char (*readPINFunction)(PORT * const me, PORT_PIN pinNumber),
                   unsigned char (*readPortFunction)(PORT * const me));

    void PORT_setDirection(PORT * const me, PORT_PIN pinNumber);
    void PORT_setStatus(PORT * const me, PORT_PIN pinNumber);
    void PORT_enablePullResistor(PORT * const me, PORT_PIN pinNumber);
    void PORT_disablePullResistor(PORT * const me, PORT_PIN pinNumber);
    void PORT_notifyPinChange(PORT * const me, PORT_PIN pinNumber);
    unsigned char PORT_readPIN(PORT * const me, PORT_PIN pinNumber);
    unsigned char PORT_readPort(PORT * const me);

    PORT * PORT_create(PORT_TYPE whichPort);
    void PORT_destroy(PORT * const me);



#endif // PORT_H_INCLUDED
#如果包括端口H#
#定义包含的端口
#包括
typedef枚举端口类型{
//ATmega328P中的所有端口
B港,
C港,
港口D
}PORT_类型;
typedef枚举端口_引脚{
//ATmega328P中的所有引脚
引脚0,
别针1,
引脚2,
引脚_3,
引脚4,
别针5,
别针6,
别针7
}PORT_PIN;
类型定义结构端口;
无效端口初始化(端口*常量),
void(*setDirectionFunction)(端口*常数me,端口号),
无效(*setStatusFunction)(端口*常数me,端口号),
无效(*启用PullResistorFunction)(端口*常数me,端口号),
无效(*禁用PullResistorFunction)(端口*常数me,端口号),
void(*notifyPinChangeFunction)(端口*常数me,端口号),
无符号字符(*readPINFunction)(端口*常数me,端口号),
无符号字符(*readPortFunction)(端口*const me));
无效端口设置方向(端口*常数,端口号);
无效端口设置状态(端口*常数,端口号);
无效端口启用Pull电阻器(端口*常数,端口引脚编号);
无效端口\禁用Pull电阻器(端口*常数,端口\引脚编号);
无效端口号(端口号*常数,端口号);
未签名字符端口号(端口号*常量,端口号);
未签名字符端口_readPort(端口*const me);
端口*端口创建(端口类型whichPort);
无效端口(端口*常数me);
#endif//包括端口号
端口.c文件

#include <avr/io.h>
#include <PORT.h>

#define ADDR_PORTB (0x0023)
#define ADDR_PORTC (0x0026)
#define ADDR_PORTD (0x0029)

typedef volatile struct{
// it is used for manipulating registers.
    unsigned char pin;
    unsigned char ddr;
    unsigned char port;
}PORT_hw;

struct PORT{
    unsigned char changePIN;
    PORT_hw volatile *p_hw;
    void (* setDirection)(PORT * const me, PORT_PIN pinNumber);
    void (* setStatus)(PORT * const me, PORT_PIN pinNumber);
    void (* enablePullResistor)(PORT * const me, PORT_PIN pinNumber);
    void (* disablePullResistor)(PORT * const me, PORT_PIN pinNumber);
    void (* notifyPinChange)(PORT * const me, PORT_PIN pinNumber);
    unsigned char (*readPIN)(PORT * const me, PORT_PIN pinNumber);
    unsigned char (*readPort)(PORT * const me);
};

static PORT g_PORT[3];
g_PORT[0].p_hw = (PORT_hw volatile *)ADDR_PORTB;
g_PORT[1].p_hw = (PORT_hw volatile *)ADDR_PORTC;
g_PORT[2].p_hw = (PORT_hw volatile *)ADDR_PORTD;

void PORT_init(PORT * const me,
                   void (* setDirectionFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* setStatusFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* enablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* disablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
                   void (* notifyPinChangeFunction)(PORT * const me, PORT_PIN pinNumber),
                   unsigned char (*readPINFunction)(PORT * const me, PORT_PIN pinNumber),
                   unsigned char (*readPortFunction)(PORT * const me)){
    me->changePIN = 0x00;
    me->pinStatus = 0x00;
    me->setDirection = setDirectionFunction;
    me->setStatus = setStatusFunction;
    me->enablePullResistor = enablePullResistorFunction;
    me->disablePullResistor = disablePullResistorFunction;
    me->notifyPinChange = notifyPinChangeFunction;
    me->readPIN = readPINFunction;
    me->readPort = readPortFunction;
}

void PORT_setDirection(PORT * const me, PORT_PIN pinNumber){}
void PORT_setStatus(PORT * const me, PORT_PIN pinNumber){}
void PORT_enablePullResistor(PORT * const me, PORT_PIN pinNumber){}
void PORT_disablePullResistor(PORT * const me, PORT_PIN pinNumber){}
void PORT_notifyPinChange(PORT * const me, PORT_PIN pinNumber){}
unsigned char PORT_readPIN(PORT * const me, PORT_PIN pinNumber){}
unsigned char PORT_readPort(PORT * const me){}


PORT * PORT_create(PORT_TYPE whichPort){
    PORT *p_PORT = &(g_PORT[whichPort]);
    PORT_init(p_PORT, PORT_setDirection, PORT_setStatus, PORT_enablePullResistor, PORT_disablePullResistor, PORT_notifyPinChange, PORT_readPIN, PORT_readPort);
    return p_PORT;
}
void PORT_destroy(PORT * const me){}
#包括
#包括
#定义地址端口B(0x0023)
#定义地址端口C(0x0026)
#定义地址端口(0x0029)
typedef volatile结构{
//它用于操作寄存器。
无符号字符引脚;
无符号字符ddr;
无符号字符端口;
}港口;;
结构端口{
无符号字符changePIN;
PORT_hw volatile*p_hw;
无效(*设置方向)(端口*常数me,端口号);
无效(*设置状态)(端口*常数me,端口号);
无效(*启用PullResistor)(端口*常数me,端口号);
无效(*禁用Pull电阻器)(端口*常数me,端口号);
无效(*notifyPinChange)(端口*常数me,端口号);
无符号字符(*readPIN)(端口*常数me,端口号);
未签名字符(*readPort)(端口*常量me);
};
静态端口g_端口[3];
g_端口[0]。p_hw=(PORT_hw volatile*)地址端口B;
g_端口[1]。p_hw=(PORT_hw volatile*)ADDR_PORTC;
g_端口[2]。p_hw=(PORT_hw volatile*)ADDR_PORTD;
无效端口初始化(端口*常量),
void(*setDirectionFunction)(端口*常数me,端口号),
无效(*setStatusFunction)(端口*常数me,端口号),
无效(*启用PullResistorFunction)(端口*常数me,端口号),
无效(*禁用PullResistorFunction)(端口*常数me,端口号),
void(*notifyPinChangeFunction)(端口*常数me,端口号),
无符号字符(*readPINFunction)(端口*常数me,端口号),
无符号字符(*readPortFunction)(端口*const me)){
me->changePIN=0x00;
me->pinStatus=0x00;
me->setDirection=setDirectionFunction;
me->setStatus=setStatus函数;
me->enablePullResistor=enablePullResistor功能;
me->disablePullResistor=disablePullResistor功能;
me->notifyPinChange=notifyPinChange函数;
me->readPIN=readPINFunction;
me->readPort=readPortFunction;
}
无效端口设置方向(端口*常量,端口号)
无效端口设置状态(端口*常量,端口号){}
无效端口\启用PullResistor(端口*常数,端口\引脚编号){}
无效端口\禁用Pull电阻器(端口*常数me,端口\引脚编号){}
无效端口号notifyPinChange(端口号*常量,端口号号){}
无符号字符PORT_readPIN(PORT*const me,PORT_PIN PIN编号){}
未签名字符端口_readPort(端口*const me){}
端口*端口创建(端口类型whichPort){
端口*p_端口=&(g_端口[哪个端口]);
PORT_init(p_PORT、PORT_setDirection、PORT_setStatus、PORT_EnablePull电阻器、PORT_DisablePull电阻器、PORT_notifyPinChange、PORT_readPIN、PORT_readPort);
返回p_端口;
}
无效端口_销毁(端口*常量){}

PORT.h头文件声明存在
struct PORT
,但未定义它:

typedef struct PORT PORT;
实际定义在PORT.c中,在main.c中不可见

因此,您无法创建类型为
PORT
的变量。但是,您可以创建一个类型为
端口*
。由于定义未知,这被称为不透明指针

根据PORT.h中定义的函数判断,您可以使用PORT\u create函数返回一个
PORT*
,该函数随后可以传递给其他函数