I am just learning C by starting on modifying an example program to do what I want it to do. But immediately get warning messages although the compiled program runs fine. Whenever I declare a variable I get the following warnings.
Measure.c(153): warning: #550-D: variable "Minn_flag" was set but never used Measure.c(62): warning: #550-D: variable "Ret_flags" was set but never used
Ret_Flags is declare as a global at the head of a file, and used in two functions. Minn_flag is declared inside a function and used once. I dont understand because I am declaring and using variables right alongside others already used in the example. Those variables dont get errors, but mine do. I am sure it's basic but what am I doing wrong?
Thanks!
The warnings mean exactly what they say: your are assigning a value to the variable, but you never do anything else with that variable.
So the compiler thinks: what's the point of having the variable, and assigning (ie, writing) a value to it, if you never use it for anything!
To be able to say anything more concrete, we'd have to see your code!
We can ask C doubts in this forum? that s nice,
rgds,
Thanks, I was using the variables just to catch some values for testing. I thought that minn = 0; was enough to keep the compiler happy. But then I added minn = minn + 1 and the warning has disappeared. So I know what you mean.
OK here's another one how can I comment chunks of C code out that I don't want compiled right now inside a function? I tried /* ..... */ But the existing comments stop that working. // on each line works but thats a pain #IF 0 ..... #ENDIF doesn't work, is there a trick or do I have to cut/copy into Notepad for instance?
Excuse these simple questions, but the Forum is the only place I can ask. At least I am making some headway into C, which pleases me at least. Thanks!
"#IF 0 ..... #ENDIF doesn't work"
Remember that 'C' is case-sensitive
You need to write #if 0 ... #endif
This can also be useful for trying-out alternative approaches:
#if 1 //do it this way #else //do it that way #endif
View all questions in Keil forum