Hi,
I defined,
Uint16 TCounts[10]; in globals.h
and tried to use it in cc01drv.c where #include "globals.h" is there.
but during build the error msg coming up is, "C202 undefined identifier"
Why this is happening, I haven't initialize the array.
Which identifier, precisely, is it saying is undefined?
Note that defining a variable in a header is a big mistake anyhow - as it will lead to multiple definitions!
You should just declare the variable as extern in the header, and have the definition in a 'C' file.
See: c-faq.com/.../decldef.html
Hi Andy, Thanks for your suggestion. I already have a program which runs fine with globals declaration as following Line 1.
globals.h line 1:volatile unsigned int xdata Temperature_Counts; line 2:volatile unsigned int xdata TCounts[10];
Now I want to add some additional code which will hold 10 temperature counts every sec. That's why I declared an array as in Line 2 above.
Line 1 variable Temperature_Counts used in adcdrv.c, calc.c successfully.
But when I used TCounts in CC01drv.c, calc.c files, it don't compile saying TCounts as undefined identifier. I added #include "globals.h" in both files. But did not initialize the array. I am trying to use TCounts in Interrupt handler function.
I hope the above explanation will give you better idea about my issue.
That is no indication that your usage is correct!
More likely, you are just "lucky" that it somehow happens not to have caused any noticeable problems in the specific case of that particular program.
In general, it is not a good idea because it will, sooner or later, cause problems!
"I hope the above explanation will give you better idea about my issue."
Sorry, but no - we'd have to see the actual code to know what you've actually done and understand why you get that error.
I realized I need to declare the variable twice like, #ifdef _MAIN_ Float32 eedata; #else extern Float32 eedata; Now, it is compiling. I need to understand it furthur details later.
But now I am facing other issue. I am trying to store the ADC readings in an array. Original decleration is,
Globals.h extern volatile unsigned int xdata TCounts; /* store for raw ADC readings*/
Now I declared, globals.h extern Uint16 RawTCounts[10];
Interrupt handlers I defined a 1 sec clock and tried to store TCounts every sec, rolling FIFO type.
RawCounts[n]=TCounts;
With output commands I found RawTCounts[n] values are far way from TCounts, like TCounts is 9359h and RawTCounts[0]= 4710h and no movement at all. Being an Electronic Engineer I don't what I'm missing!! I put the assignment command inside the calc.c function where original TCounts were used then moved it to interrupt handler thinking it might miss the Flag etc.
View all questions in Keil forum