As a newbie to C, I am confused when the hover is actually normal.
As I understand it, you can use any type of pointer for any other type, and the compiler will let you do this. For example:
int a = 5; int* intPtr = &a; char* charPtr = (char*) intPtr;
However, as a rule, this causes undefined behavior (although it works on many platforms). However, there are apparently some exceptions:
- you can freely click on and from
void* (?) - you can freely click on and from
char* (?)
(at least I saw it in code ...).
So what are the between types of pointer non-undefined behavior in C?
Edit:
I tried to learn the C standard (section "6.3.2.3 Pointers", http://c0x.coding-guidelines.com/6.3.2.3.html ), but actually figure it out, except for the bit about void* .
Edit2:
Just for clarification: I am explicitly asking only for โnormalโ pointers, i.e. not about function pointers. I understand that the rules for cast function pointers are very limited. As far as I remember, I already asked about this :-): What happens if I draw a pointer to a function by changing the number of parameters
c casting undefined-behavior
sleske Jan 26 2018-11-21T00: 00Z
source share