Hello,
Being here just 30 seconds.
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 that fc4 undefined, see it
error: #20: identifier "fc4" is undefined
The second one is about using an integer function in other file. It is actually another attempt of the one above.
I failed to use the typedef union in other file. Instead, I define a variable of float in file a.c and redeclare 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.
It's best to stick to one question per thread - otherwise replies to the different questions get muddled up.
As 42Bastian Schick says, this is standard 'C' stuff - nothing specifically to do with ARM or Cortex-M
Here are some standard 'C' reference & learning materials for you:
https://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/
MakeItGREATagain said:Compiler gives an error telling that fc4 undefined, see it error: #20: identifier "fc4" is undefined
So where, exactly, was that error reported?
MakeItGREATagain said: // a.c fc4 vfc4a;
// a.c fc4 vfc4a;
So your a.c file has not #included the a.h header ?