A warning message is given when the compiler discovers that there is a problem in the program and there may be problems. Warning messages can mean large errors that are implied in the program, or they may not be a problem. The correct way to handle a warning should be: eliminate it as much as possible. Each warning given by the compiler should be analyzed carefully to see if there is a real problem. Only those warnings that do not really matter can be put down.
Description
As a result of the compilation of a variety of warnings, can not be listed at all, the following is only a few of the more typical warnings, and some warnings, as long as the literal meaning, you can quickly find out, and to solve it.
Type 1:
showing: warning:implicit declaration of function ' Example () '.
Warning Reason:
The function example () was called in your. c file, but you didn't include the corresponding. h file that declares the function.
It is possible that you defined this function body in a. c file, but did not declare it in. h.
Workaround:
You can add: extern Example () at the beginning of the. c file that calls this function.
You can include a header file that declares the function example () in the. c file that calls this function.
If you have defined this function body in a. c file, but have not declared it in. h, you can also generate an. h file, plus your function declaration.
A similar warning:
Warning:type mismatch with previous implicit declaration
Warning:type mismatch with previous implicit declaration
Warning:previous implicit declaration of ' Example () '
Type 2:
Show: warning:unused variable ' param '.
Warning Reason: Obviously, you defined the variable ' param ', but you didn't use it at all.
Workaround : Delete it if you don't need it.
Type 3:
display:warning:statement with no effect.
Warning Reason: The possible situation is that in your file, you do so #define Macroprint
The #define MACROPRINT printf is then defined in one place. And then you're quoting everywhere
Macroprint ("HELLO"), so there is no error, but there is a warning "this statement is useless."
Solution : Delete the #define Macroprint.
Type 4:
showing:warning:int format, long int arg (ARG 3)
Warning reason: like this printf ("%s%d, szdebugstring, Ulgwid"), your ulgwid is a unsigned long type, and the output you choose for it is "%d" (this format is-int for the integer service).
solution : Such a mistake you just have to do the same parameter type, like the above phenomenon, you just change "%d" to "%d" on it.
Similar warning: Warning:comparison between pointer and integer
Type 5:
showing:Warning:comparison is always 0 due to limited range of data type
Warning Reason: It is possible that you have defined the unsigned int uparam; but you do the judgment of if (uparam<0),
Because the data for the unsigned int is always >=0, this comparison gives a warning because the data type restricts its scope.
Solution : You can get rid of such judgments.
Type 6:
showing:Warning:control reaches end of non-void function
Warning Reason: There is such a warning that it is possible that you wrote a
unsigned long Funca ()
{
if ()
{return
ulvalue;
}
if ()
{return
ulvalue
}
}
Such a function, perhaps in two if statements, you do not enter, at which point, before exiting the function, you have no value to return.
workaround : If a function has a return value, make sure that the function has a return value in any case.
Similar warning: Warning: ' Return ' with no value, in function returning non-void
Type 7:
showing:warning:overflow in implicit constant conversion
Warning Reason: The transformation of a variable may cause a value to be crossed.
#define Ret_productid 0x10000000
#define Err_ret_global ret_productid+5000
#define Ret_user err_ret_global+ 5000
#define USER_OK ret_user+0
#define User_fail ret_user+1
If this definition is encountered, the short Func () {return USER_OK} will be alerted to the occurrence of a cross border.
solution : Determine the range of good values.
Type 8:
showing:warning: ' Ulparam ' might be used uninitialized in this function
Warning Reason: When Ulparam is the right value for an expression, you have not initialized this parameter before.
For example:
void Func ()
{
ulong Ulparam;
ULONG Ulretcode;
if (...)
{
Ulparam = ...
}
if (...)
{
Ulparam =. ...
}
Ulretcode = Ulparam;
}
In this case, when the two if () is not implemented, Ulparam is not assigned to the value, so that the Ulretcode to assign value, it is more dangerous.
solution : Leave more than one God and be more careful.
Type 9:
showing: warning:passing arg 1 of ' free ' makes pointer from integer without a cast
Warning Reason: You free (a), but a is a unsigned long, you may put a pointer to the value of the inside of a.
workaround : At Free (a), you need to cast a to a pointer type. That is: Free ((char*) a).
Similar warning:warning:assignment from incompatible pointer type
Warning:initialization from incompatible pointer type
Warning:passing Arg 2 of ' aos_memcopy_x ' makes pointer from integer without a cast
Type 10:
Show: warning: ' My_debug ' redefined
Warning:this is the location of the previous definition
Warning Reason: There are two consecutive warnings, and one possibility is that you include two. h in your. c file.
Files, and these two. h files are declared to My_debug.
workaround : Declare this in just one file.
Type 11:
showing:Warning:value computed is not used
Warning Reason: The value of the participating operation is not useful. Like you do:
Char* p;
*p++;
This has no effect on p at all.
workaround : Make sure what you want to do with the operation.
Type 12:
showing:warning: ' #ifdef ' argument starts with a digit
Warning Reason: There is a mistake like #ifdef 0
Solution : It should be #if 0.
Type 13:
Show:warning:unknown escape sequence ' \ r '
Warning Reason: compiler does not know ' \ R '.
workaround : A clerical error should be ' \ R '.
Type 14:
displayed:warning:too few arguments for format
Warning Reason: You may have done this: printf ("%d%s", Uparam);
Solution : Leave what you want, don't remove it.
Type 15:
showing:warning: ' Func ' defined but not used
Warning Reason: The FUNC function you defined, but you did not use it at all.
The solution : Do not remove it.
Type 16:
Show:warning:suggest parentheses around && within | |
Warning Reason: someone used that.
if ((*p >= ' a ') && (*p <= ' z ') | | (*p >= ' A ') && (*p <= ' Z ') | | (*p >= ' 0 ") && (*p <= ' 9 '))
Solution : You better do it.
if ((*p >= ' a ') && (*p <= ' z ') | | (*p >= ' a ') && (*p <= ' z ')) | (*p >= ' 0 ') & amp;& (*p <= ' 9 '))