Keil MDK compiler warning and error details (occasionally updated)

Source: Internet
Author: User

After work, I switched from a single-chip computer to an arm. At the beginning, I used the ads1.2 compiler for a while, because the old program I took over was compiled using ads, and most departments were using it. when learning SCM, we use the Keil C51 compiler. ads and this compiler cannot be compared in terms of ease of use. later, we gradually learned that Keil has been acquired by arm, and now Keil MDK has become an official arm compiler, so we decided to re-run Keil and re-compile the original program with MDK using the usual time. the advantages of MDK are unnecessary. Here, we will give a detailed explanation of the warning and error information provided by the compiler, hoping to help beginners and find errors. Please leave a message if necessary.


1. Warning: # 550-d: variable "D" was set but never used
Description: The variable 'D' is defined but never used. Alternatively, although you use this variable, the compiler considers the statement where variable D is located meaningless and the compiler optimizes it.
Solution: carefully measure whether the defined variable D is useful. If it is determined that the statement where the variable D is located makes sense, try to use the volatile keyword to modify the variable D. If it is useless, delete the memory to release the 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 be a blank line. I thought for a long time Why I didn't figure it out.
Solution: Ignore it. If you feel that a warning is not satisfactory, press enter in the last line of the warning file to empty a line.

3. Warning: # 111-d: Statement is unreachable
Description: it is not possible to declare that it will arrive. This is an example:
Int main (void)

While (1) // infinite loop, which is the most common in programs that do not use the Operating System


Return 0; // This statement cannot be executed normally, and the compiler issues a warning.
Solution: Ignore the meeting.

4. Warning: c3017w: data may be used before being set
Description: The variable 'data' is not explicitly assigned before use. For example:
Uint8 I, data; // defines the variables I and data.

For (I = 0; I <8; I ++) // The variable 'I' is assigned 0 in the statement.
If (io1pin & so_cc2420)
Data | = 0x01; // The variable 'data' is not explicitly assigned before use, and the compiler issues a warning
Data & = ~ 0x01;
Solution: Check whether the initial value of the variable is 0. If yes, ignore this warning because the MDK compiler initializes the used data zone to 0 before executing the program, however, if the initial value of the variable is not 0, ignoring this warning may cause a fatal error. this warning should be paid enough attention. the habit of assigning initial values to variables should be developed. Fortunately, there is a compiler to check.

5. Warning: # 177-d: variable "Temp" was declared but never referenced
Description: The variable 'temp 'is declared but not referenced. A variable is declared but not used. It differs from warning: # 550-d: variable "Temp" was set but never used because temp has never been used.
Solution: If the Defined variables are useless, delete them. If they are useful, use them in the program.
Similar to this warning, there are also 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: return the final missing return value declaration of the non-empty function "dealwithinspect2". For example:
Int dealwithinspect2 (uint32 test)
// Return X; return an int data. If no return value is returned, 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 parameter, this warning will be triggered, for example, void timer_init (); there is no form parameter here. If so, the compiler will give a warning.






1. Error: #65: expected ";"
Description: The semicolon is missing. Most of them are missing ';'.
Solution: double-click the error line. Find the statement without the ';' near the error point, and add a semicolon. the semicolon is not necessarily located in the wrong line. It may be the previous line or the next line.

2. Error: #65: expected a ";" and error: #20: identifier "XXXX" is undefined, and the following error: #20 may cause many errors.
Description: This error is definitely a nightmare for the first person you encounter. When an error occurs, double-click the error prompt with hope. When the error arrives, you can find that the error line is absolutely correct, so look for the last line of the wrong line, the next line, there is no error, find the last line, the next downlink... a depressing thing has emerged: All the error lines prompted by the compilation cannot have errors. in fact, this is most likely because you are. when an H file declares an external variable or function, no extra points are given at the end of the statement declaration! If you have many modules, such as main. c, LCD. c, key. c... there are many header files, such as LCD. h, key. h. if the H file declares a function without a plus sign, this error may be set to main. c, so check all header files.
Solution: Check the. h file carefully and add the semicolon.

3. Error: l6200e: Symbol flagu multiply defined (by uart0.o and Main. O ).

Description: Multiple flagu definitions (in uart0.c and Main. c ). generally, the global variable definition is duplicated. for example, in Main. define the global variable flagu in C:

Uint8 flagu = 0;

This variable is also used in uart0.c, So I declare this variable. I usually copy the defined variable first and then add the keyword extern before the variable:

Extern uint8 flagu = 0;

After compilation, the above connection error occurs because I defined another variable in uart0.c instead of declaring the variable, because I assigned the initial value "flagu = 0" to the variable, the variable flag is repeatedly defined. the correct declaration method is to remove the assignment part:

Extern uint8 flagu;

Solution: Find the variable that has been repeatedly defined and modify it as needed.

4. Error: #159: Declaration is incompatible with previous "wr_ LCD" (declared at line 40)
Description: It is used before the wr_ LCD function is declared. there are two more cases: first, wr_ LCD function has been used before it is written. In this case, it is usually written into the general structure of a program, just a simple framework. the second case is more common. function a calls function B, but the function body of function B is under function:
Void A (void) // The entity of function
B (); // call function B

Void B (void) // The entity of function B
In this way, if you click compile, the error: #159 will be generated, because when function a calls function B, it is found that no declaration of function B has been made before.
Solution: declare function B before function a calls function B, for example:
Void B (void); // declare function B

Void A (void) // The entity of function
B (); // call function B

Void B (void) // The entity of function B
5. Error: #137: expression must be a modifiable lvalue

Description: The expression must be a modifiable left value. This phenomenon mainly occurs:

A = num;

Num is a value or expression. A is a variable, but a is defined as an unchangeable type like Const. As a result, num cannot be assigned to variable.

Solution: either discard the value assignment or modify the variable attributes.

6. Error: #18: expected ")"
If it appears in the C file, it is mostly because one ")" is missing, or the error line contains characters not recognized by the compiler.

If it appears in the header file, the error line is a function declaration, mostly because there are characters not recognized by the compiler in the function declaration.

7. Error: #7: Unrecognized token

Unrecognized tags, most of which are switched to Chinese punctuation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.