After working with microcontrollers, I transitioned to ARM and initially used the ADS 1.2 compiler. I used it for a while because the old program of the project I took over was compiled with ADS, and most of the department was using it. When learning about microcontrollers, I used the Keil C51 compiler, and the usability of ADS cannot be compared to this compiler. Gradually, I learned that Keil had been acquired by ARM, and now Keil MDK has become the official ARM compiler. Therefore, I decided to switch back to Keil and use my spare time to recompile the original program with MDK. There’s no need to mention the advantages of MDK here; I will provide a detailed explanation of the warnings and error messages given by the compiler that I encountered, hoping to help beginners. If there are any mistakes or additions, feel free to leave a message.
1. warning: #550-D: variable “d” was set but never used
Description: The variable ‘d’ is defined but never used, or, although you used this variable, the compiler thinks that the statement containing variable ‘d’ has no meaning, so it optimized it away.
Solution: Carefully consider whether the defined variable ‘d’ is useful. If you determine that the statement containing variable ‘d’ is meaningful, try to use the volatile keyword to modify variable ‘d’. If it really is not useful, delete it to free up possible memory.
2. warning: #1-D: last line of file ends without a newline
Description: The last line of the file is not a new line. The compiler requires that the last line of the program file must be empty. I thought for a long time and couldn’t figure out why it should be this way.
Solution: You can ignore it. If you feel uncomfortable with the warning, then press Enter on the last line of the file with the warning to leave an empty line.
3. warning: #111-D: statement is unreachable
Description: The statement cannot be reached. This often occurs in scenarios like:
int main(void)
{
…
while(1) // infinite loop, this is most common in programs that do not use an operating system
{
…
}
return 0; // this statement cannot be executed under normal circumstances, the compiler issues a warning
}
Solution: Ignore it.
4. warning: C3017W: data may be used before being set
Description: The variable ‘data’ has not been explicitly assigned a value before use. For example:
uint8 i, data; // define variables i and data, neither has an explicit value
for (i = 0; i < 8; i++) // variable ‘i’ is assigned 0 in this statement
{
if (IO1PIN & SO_CC2420)
data |= 0x01; // variable ‘data’ has not been explicitly assigned a value before use, the compiler issues a warning
else
data &= ~0x01;
}
Solution: Carefully consider whether the initial value of this variable is 0. If so, you can ignore this warning because the MDK compiler will initialize the data area to 0 before the program executes. However, if the initial value of this variable should not be 0, ignoring this warning may cause fatal errors. This warning should be taken seriously. You should develop the habit of initializing variables to ensure that the compiler checks them.
5. warning: #177-D: variable “temp” was declared but never referenced
Description: The variable ‘temp’ was declared but not referenced. This often occurs when a variable is declared but never used. It differs from warning: #550-D: variable “temp” was set but never used in that ‘temp’ has never been used.
Solution: If the defined variable is indeed not useful, delete it; if it is useful, use it in the program.
Similar to this warning is warning: #177-D: function “MACProcessBeacon” was declared but never referenced.
6. warning: #940-D: missing return statement at end of non-void function “DealwithInspect2”
Description: The last return value declaration is missing for the non-void function “DealwithInspect2”. For example:
int DealwithInspect2(uint32 test)
{
…
…
…
// here should be return x; to return an int type data. If there is no return value, the compiler generates a warning
}
7. warning: #1295-D: Deprecated declaration lcd_init – give arg types
Description: When defining a function, if you write the function parameters, you will receive this warning, for example void timer_init(); here there are no parameters, if this is the case, the compiler will give a warning.
1. error: #65: expected a “;”
Description: Missing semicolon. Most of the time, it’s because of forgetting to add a ‘;’.
Solution: Double-click the error line, find the statement near the error point that is missing the ‘;’ and add the semicolon. It doesn’t necessarily have to be on the error line; it could be on the previous line or the next line.
2. error: #65: expected a “;” and error: #20: identifier “xxxx” is undefined often appear together, and the subsequent error: #20 may have many.
Description: This error is definitely a nightmare for first-time encounters. When the error occurs, you double-click the error message with hope, and when you arrive at the error line, you are astonished to find that the error line is absolutely correct. So you look for the error line above, below, and find no errors. Then you look for the line above that, below that… It’s extremely frustrating: the compilation hints that all the error lines cannot have errors. In fact, this is most likely because when declaring external variables or functions in the .h file, you forgot to add a semicolon at the end of the declaration! If you have many modules, like main.c, lcd.c, key.c… and many header files, like lcd.h, key.h, if you forgot to add a semicolon when declaring a function in the lcd.h file, this error may propagate to main.c, so you need to check all header files.
Solution: Carefully check the .h files and add the semicolons.
3. Error: L6200E: Symbol flagu multiply defined (by uart0.o and main.o).
Description: The variable (also a symbol) flagu is defined multiple times (defined in both uart0.c and main.c). Usually, it’s due to a global variable being defined multiple times. For example, if you define a global variable flagu in main.c:
uint8 flagu=0;
And you use this variable in uart0.c, I usually copy the defined variable and add the extern keyword in front of it:
extern uint8 flagu=0;
Then compile, and you will see the above linking error. The reason is that I defined another variable in uart0.c instead of declaring the variable because I assigned an initial value “flagu=0”, which caused the variable flag to be defined multiple times. The correct declaration method is to remove the assignment part:
extern uint8 flagu;
Solution: Find the variable that is defined multiple times and modify one of them as needed.
4. error: #159: declaration is incompatible with previous “wr_lcd” (declared at line 40)
Description: The function wr_lcd was used before it was declared. This often occurs in two situations: first, the body of the wr_lcd function has not been written yet, but it has already been used. This situation often occurs when writing a rough structure of a program, just simply writing a framework. The second situation is more common, where function a calls function b, but the body of function b is below function a:
void a(void) // body of function a
{
b(); // calling function b
}
void b(void) // body of function b
{
…
}
Thus, if you compile, it will produce error: #159 because when function a calls function b, it finds that there has been no declaration of function b beforehand.
Solution: Declare function b before it is called by function a, for example:
void b(void); // declare function b
void a(void) // body of function a
{
b(); // calling function b
}
void b(void) // body of function b
{
…
}
5. error: #137: expression must be a modifiable lvalue
Description: The expression must be a modifiable lvalue. This mainly appears in situations like:
a=NUM;
NUM is a value or expression, a is a variable, but ‘a’ is defined as an unmodifiable type like const, causing NUM cannot be assigned to variable ‘a’.
Solution: Either give up the assignment or modify the variable attributes.
6. error: #18: expected a “)”
If it appears in the c file, it is mostly because a “)” is missing, or the error line has characters that the compiler does not recognize.
If it appears in the header file, and the error line is a function declaration, it is mostly because there are characters in the function declaration that the compiler does not recognize.
7. error: #7: unrecognized token
Unrecognized token, most likely due to switching to Chinese punctuation.