...
The C Standard allows any object pointer to be cast to and from void *. As a result, it is possible to silently convert from one pointer type to another without the compiler diagnosing the problem by storing or casting a pointer to void * and then storing or casting it to the final type. In this noncompliant code example, loop_function() is passed the char pointer loopchar_ptr but returns an object of type int pointer:
| Code Block | ||||
|---|---|---|---|---|
| ||||
int *loop_function(void *v_pointer) {
/* ... */
return v_pointer;
}
void func(char *loopchar_ptr) {
int *int_ptr = loop_function(loopchar_ptr);
/* ... */
} |
This example compiles without warning using GCC 4.8 on Ubuntu Linux 14.04. However, v_pointer can be more strictly aligned than an object of type int *.
...