模块化C编码中的结构定义 [英] Structure definition in modular c coding

查看:113
本文介绍了模块化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

推荐答案

如果要在不同的C文件中使用xdata ,将其声明移至.h文件,并在所有需要使用xdata的C文件中将其声明#include.

xdata.h
If you want to use xdata into different C file, move its declaration into an .h file and #include it in all the C files that require to use xdata.

xdata.h
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编码中的结构定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆