一个文件中定义的整型函数 在另一个文件中调用 要extern吗 include发现这个函数被跳过了 得不到执行
但void的函数就没有这种问题 细节是下边这种 没翻译直接粘贴了
I have two questions, where the first one is about using a typdef union{} in other files, see my code here
// a.h
typedef union{
float vf;
unsigned char vuc[4];
}fc4;
// a.c
fc4 vfc4a;
// b.c
#include "a.h"
extern fc4 vfc4a;
Compiler gives an error telling fc4 undefined, see it
error: #20: identifier "fc4" is undefined
The second one is about using an integer function in aother file. It is actually another attempt of the one above.
I failed to use the typedef union in other files. Instead, I define a variable of float in file a.c and re-declare it as extern in a global .h file which was included in file b.c, see this.
// a.c
fc4 vfc4a;
float vfa;
int Parsing(void)
{
for(int i=0; i<4; i++)
vfc4a.vuc[i] = RxBuf[i]; // suppose there is a valid RxBuf from the serial
vfa = vfc4a.df;
printf("%s %f\n", "In parsing()", vfa);
return 1;
}
// b.c
#include "global.h" // extern float vfa in this.
void a_function(void)
{
int ret = Parsing();
if(ret)
printf("%s %f\n", "In b.c", vfa);
for(int i=0; i<4; i++)
printf("%x ", vfc4a.vuc[i]);
printf("\n");
}
printf() is redirected to a serial port sending data to a PC. The PC can receive output given by printf in a_function but cannot receive the one in Parsing(). Besides, vfa in a_function is always 0 including the case that RxBuf is not 0.
--
FROM 106.39.0.*