One code:
Copy codeThe Code is as follows: # include <stdio. h>
# Include <stdlib. h>
# Define uchar unsigned char
# Define uint unsigned int
Void display (uchar * p );
Char h [4] = {'A', 'B', 'C', '\ 0 '};
Char e [4] = {'E', 'F', 'l', '\ 0 '};
Char l [4] = {'M', 'n', 'O', '\ 0 '};
Char o [4] = {'x', 'y', 'z', '\ 0 '};
Int main (void)
{
Int I;
Char c;
Uint set [5];
Set [0] = h;
Set [1] = e;
Set [2] = l;
Set [3] = l;
Set [4] = o;
While (1 ){
For (I = 0; I <5; ++ I ){
Display (set [I]);
Printf ("\ n ");
Sleep (1 );
}
}
}
Void display (uchar * p)
{
While (* p! = '\ 0 '){
Printf ("% c", * p );
Printf ("% c", * (p + 1 ));
++ P;
}
}
The alarm is as follows:
Test. c: 21: warning: the pointer is assigned to an integer when the value is assigned. No type conversion is performed.
Test. c: 22: warning: the pointer is assigned to an integer when the value is assigned. No type conversion is performed.
Test. c: 23: warning: the pointer is assigned to an integer when the value is assigned. No type conversion is performed.
Test. c: 24: warning: the pointer is assigned to an integer when the value is assigned. No type conversion is performed.
Test. c: 25: warning: the pointer is assigned to an integer when the value is assigned. No type conversion is performed.
Test. c: 29: warning: the integer is assigned to the pointer when parameter 1 ('display') is passed, without type conversion
Where 21-25 is
Set [0] = h;
Set [1] = e;
Set [2] = l;
Set [3] = l;
Set [4] = o;
29 Yes
Display (set [I])
Although it is only an alert and can run well in linux, it is worth discussing.
To be continued ~
Watching...
If anyone knows, can you reply to me? Thank you ~
------------------------------------------------------------
For this question, I asked ding in the dormitory. After his modification, the program had no warning.
Copy codeThe Code is as follows: # include <stdio. h>
# Include <stdlib. h>
# Define uchar unsigned char
# Define uint unsigned int
Void display (uchar * p );
Char h [4] = {'A', 'B', 'C', '\ 0 '};
Char e [4] = {'E', 'F', 'l', '\ 0 '};
Char l [4] = {'M', 'n', 'O', '\ 0 '};
Char o [4] = {'x', 'y', 'z', '\ 0 '};
Int main (void)
{
Int I;
Char c;
Int set [5];
Set [0] = (int) h;
Set [1] = (int) e;
Set [2] = (int) l;
Set [3] = (int) l;
Set [4] = (int) o;
While (1 ){
For (I = 0; I <5; ++ I ){
Display (uchar *) set [I]);
Printf ("\ n ");
Sleep (1 );
}
}
}
Void display (uchar * p)
{
While (* p! = '\ 0 '){
Printf ("% c", * p );
Printf ("% c", * (p + 1 ));
++ P;
}
}
Forced conversion to int is used in the assignment of the first address of the modulo array. in terms of function calls. because the input is a pointer in the subfunction, you cannot simply write set [I] during the previous call. instead, the pointer is passed. (uchar *) Forced type conversion is used in combination with (uchar * p ).
-------------------------------------------
Note the following two points:
1. Only the address and value can be transferred to the pointer. Otherwise, a forced type conversion is required.
2. When performing type conversion and value assignment, you should pay attention to the type matching of the value assignment.