S
somenath
Hi All,
I have couple of question regarding pointer assignment. I am trying to
understand pointer assignment from signed type to unsigned vice versa.
For that I wrote the bellow mentioned code.
Code 1)
#include <stdio.h>
int main(void)
{
unsigned int test = 5;
unsigned int *uintP=&test;
signed int *sintP =NULL;
sintP = uintP;
return 0;
}
While I was compiling my compiler throws the bellow mentioned warning
src\hello.c", line 7: warning #513-D: a value of type "unsigned int *"
cannot
be assigned to an entity of type "signed int *"
sintP = uintP;
^
"src\hello.c", line 6: warning #550-D: variable "sintP" was set but
never used
signed int *sintP =NULL;
When I change the code as mentioned bellow I get the same type of
warning
Code 2)
#include <stdio.h>
int main(void)
{
unsigned int test = 5;
unsigned int *uintP=&test;
signed int *sintP =NULL;
uintP = sintP;
return 0;
}
"src\hello.c", line 7: warning #513-D: a value of type "signed int *"
cannot
be assigned to an entity of type "unsigned int *"
uintP = sintP;
^
"src\hello.c", line 5: warning #550-D: variable "uintP" was set but
never used
unsigned int *uintP=&test;
^
And if I use cast then compiler does not throw warning for the
pointer assignment
Code 3)
#include <stdio.h>
int main(void)
{
unsigned int test = 5;
unsigned int *uintP=&test;
signed int *sintP =NULL;
sintP = (signed int *)uintP;
return 0;
}
Building C:\Documents and Settings\somanath\My Documents\My Projects
\Project6\default.gpj
Compiling hello.c because hello.o does not exist
"src\hello.c", line 6: warning #550-D: variable "sintP" was set but
never used
signed int *sintP =NULL;
^
My questions are
1) Is not legal to assign pointer to unsigned type to pointer to
signed type? As the pointer size is same.
2) If I use cast for the above example will it work properly always?
Regards,
Somenath
I have couple of question regarding pointer assignment. I am trying to
understand pointer assignment from signed type to unsigned vice versa.
For that I wrote the bellow mentioned code.
Code 1)
#include <stdio.h>
int main(void)
{
unsigned int test = 5;
unsigned int *uintP=&test;
signed int *sintP =NULL;
sintP = uintP;
return 0;
}
While I was compiling my compiler throws the bellow mentioned warning
src\hello.c", line 7: warning #513-D: a value of type "unsigned int *"
cannot
be assigned to an entity of type "signed int *"
sintP = uintP;
^
"src\hello.c", line 6: warning #550-D: variable "sintP" was set but
never used
signed int *sintP =NULL;
When I change the code as mentioned bellow I get the same type of
warning
Code 2)
#include <stdio.h>
int main(void)
{
unsigned int test = 5;
unsigned int *uintP=&test;
signed int *sintP =NULL;
uintP = sintP;
return 0;
}
"src\hello.c", line 7: warning #513-D: a value of type "signed int *"
cannot
be assigned to an entity of type "unsigned int *"
uintP = sintP;
^
"src\hello.c", line 5: warning #550-D: variable "uintP" was set but
never used
unsigned int *uintP=&test;
^
And if I use cast then compiler does not throw warning for the
pointer assignment
Code 3)
#include <stdio.h>
int main(void)
{
unsigned int test = 5;
unsigned int *uintP=&test;
signed int *sintP =NULL;
sintP = (signed int *)uintP;
return 0;
}
Building C:\Documents and Settings\somanath\My Documents\My Projects
\Project6\default.gpj
Compiling hello.c because hello.o does not exist
"src\hello.c", line 6: warning #550-D: variable "sintP" was set but
never used
signed int *sintP =NULL;
^
My questions are
1) Is not legal to assign pointer to unsigned type to pointer to
signed type? As the pointer size is same.
2) If I use cast for the above example will it work properly always?
Regards,
Somenath