Does the following scenario have undefined behavior?
void do_stuff(const int *const_pointer, int *pointer) {
printf("%i\n", *const_pointer);
*pointer = 1;
}
int data = 0;
do_stuff(&data, &data);
If this is undefined behavior it could probably cause problems if the compiler assumes that the value that const_pointer
points to never changes. In this case it might reorder both instructions in do_stuff
and thereby change the behavior from the intended printf("0")
to printf("1")
.