单片机里写c语言 .h 和.c文件, 关于字符数组的问题

.h文件中声明了个全局变量数组 extern unsigned char a[];
.c文件中,定义这个数组的时候: a[30]; 这样的话提示‘a’重定义了
如果.c文件中不定义这个数组,直接在子函数里用,又提示很多警告。
求解,该怎么办,想声明个全局数组变量,然后各个.c文件中的子函数中用

作标记,
.h文件中写入:

#ifndef ARRAYA
unsigned char a[];
#define ARRAYA

#else
extern unsigned char a[];
#endif

在各个子函数文件头引用.h之前,加上
#define ARRAYA追问

加过了,还是不行
#ifndef __COM_H_
#define __COM_H_
#include
extern unsigned char str[30];
#endif

追答

各个子函数文件头引用.h之前,加这个没有:
#define __COM_H_

追问

加了,说的是这个吗
#ifndef __COM_H_
#define __COM_H_
#include
extern unsigned char a[30];
void dcomp(unsigned char recive[],unsigned char send[]);
#endif

追答

把30去掉
extern unsigned char a[];

追问

解决了 ,在.c文件中这样定义就行了 unsigned char a[30]={0};
谢谢了

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答