本文介绍了模块化C编码中的结构定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在我的项目中使用结构.
我已经在文件main.c中定义了结构集,并希望在temperature.c文件中使用它的名称为peak


main.c

i am using structure in my project.
i have define structure Set in the file main.c and wanted to use it with name peak in temperature.c file


main.c

typedef xdata union
{
    unsigned char Data[8];
    struct
    {
        unsigned char Temp;
        unsigned char Hr;
        unsigned char Min;
        unsigned char Sec;
        unsigned char am_pm;
        unsigned char Date;
        unsigned char Month;
        unsigned char Year;
    }Set;
}Samples;

xdata Samples local,peak;






温度.c






temperature.c

extern union Samples peak;

void check_peak(void)
{
    if(Dec_TEMP>MAX_TEMP)
    {
        MAX_TEMP=Dec_TEMP;
//if Temp is MAX than prev ... store it to temp buffer
                    EA=0;
                    peak.Set.Temp=(unsigned char)MAX_TEMP;
                    BCD2ASCII(hour,temp);
                    peak.Set.Hr=atoi(temp);
                    BCD2ASCII(min,temp);
                    peak.Set.Min=atoi(temp);
                    BCD2ASCII(sec,temp);
                    peak.Set.Sec=atoi(temp);
                    peak.Set.am_pm=(AM_PM & 0x20);  //am/pm
                    BCD2ASCII(date,temp);
                    peak.Set.Date=atoi(temp);
                    BCD2ASCII(month,temp);
                    peak.Set.Month=atoi(temp);
                    BCD2ASCII(year,temp);
                    peak.Set.Year=atoi(temp);
                    EA=1;
    }
}




梳理时的错误是

.. \ TEMPERATURE.C(52):错误C230:``示例'':未知的struct/union/enum标签
.. \ TEMPERATURE.C(52):错误C230:设置":未定义的成员




the error while comliping is

..\TEMPERATURE.C(52) : error C230: ''Samples'':unknown struct/union/enum tag
..\TEMPERATURE.C(52) : error C230: ''Set'' : undefined member

推荐答案

typedef xdata union
{ ... } ...
extern xdata Samples ... //just let everyone know about Sample existence



main.c



main.c

#include "xdata.h"
xdata Samples ... //actually MAKE samples to exist!
...



温度.c



temperature.c

#include "xdata.h"
void check_peak(void)
{ ...}


这篇关于模块化C编码中的结构定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 17:38