W
WaterWalk
Hello. When I practice pointers, I write code like the following:
int *pn1;
void **pv = (void **)&pn1;
*pv = malloc(sizeof(int));
*pn1 = 1;
It seems to work. But when I consult n1124(the draft c99 standard with
tc2), in section 6.3.2.3/7, it says:
"A pointer to an object or incomplete type may be converted to a
pointer to a different
object or incomplete type. If the resulting pointer is not correctly
aligned for the
pointed-to type, the behavior is undefined."
It seems this statement fits the above code. Since no document says
whether (void **) is properly aligned for (int **), is the above code
potentially dangerous?
int *pn1;
void **pv = (void **)&pn1;
*pv = malloc(sizeof(int));
*pn1 = 1;
It seems to work. But when I consult n1124(the draft c99 standard with
tc2), in section 6.3.2.3/7, it says:
"A pointer to an object or incomplete type may be converted to a
pointer to a different
object or incomplete type. If the resulting pointer is not correctly
aligned for the
pointed-to type, the behavior is undefined."
It seems this statement fits the above code. Since no document says
whether (void **) is properly aligned for (int **), is the above code
potentially dangerous?