您现在的位置: 爱51代码网 >> 范文 >> 文章正文
keil中不同源文件中数组的引用

keil中不同源文件中数组的引用

最近在做一个写大量的数据到EEPROM的项目,因为数据量太大,所以我把数据单独地放到了一个源文件中,命名为data.c.比如:const unsigned char code data1[]={
0x03,0xDE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x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xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};我现在要在main.c源文件中的main函数中得到这个数组的大小,我想用sizeof(data1)来获得这个数组的大小,同时我在mian.c的头文件中加入了extern const unsigned char code data1[];我在编译的时候,没有提示错误,但是有许多警告,我看了一下,是说sizeof(data1)返回值为0,搞了好久了还是不行,该如何解决这个问题呢?假如把这个数组放到main.c源文件中,就不会有这样的问题,但是因为数据量太大了,不可能都都放在main.c中

keil51中某些版本似乎是这样,应该是个bug吧,下面是建议的解决方法

1. 把data.c从工程中删掉,然后再main.c中头部直接引用data.c,如下

#include "data.c"

2. 不删除data.c, 在data.c中加入几个求数组长度的函数,函数内部使用sizeof()求长度,在其他文件中调用这个函数来求得长度。

  • 上一篇文章:

  • 下一篇文章:
  • 最新文章 热点文章 相关文章
    java如何判断一个字符串里的数字
    随机找出24个不一样的字,在把一
    java怎么实现html转为pdf
    lotus数据列表文档个数如何实时统
    lotus代理中LS如何将字符串保存到
    在lotus BS系统里怎样方便实现统
    undefined reference timer_crea
    linux文件/usr/lib破坏了,还原后
    linux上运行system函数时,print
    Failed to open eth0
    undefined reference timer_crea
    Failed to open eth0
    C/C++洗牌算法源代码
    ZOJ 3700 Ever Dream 文章中单词
    TortoiseGit和msysGit安装及使用
    sharepoint 2010 获取用户信息Us
    设计包含max函数的队列
    mysql主从同步延迟方案解决的学习
    生日旅行总结
    中小板生日快乐随感
    单片机检测矿泉水瓶是否倒立
    keil中不同源文件中数组的引
    wince怎么让平台和设备改为不
    如何不重启系统更改WINCE的M
    单片机通信过程中的控制命令
    STM32的AHB和APB有什么关系?
    wince5.0模拟器下用GDI实心画
    操作系统的执行中断程序后的
    vs2005开发WINCE6.0应用程序
    VS2005的MFC做WINCE5.0的人机
     



    设为首页 | 加入收藏 | 网站地图 | 友情链接 |