|
|
|
|
|
by cryptonector
1730 days ago
|
|
Comparing the uintptr_t cast of two disparate pointers is not undefined behavior. A comparison may not yield a portable result because the integer representation of pointers may not be as plain memory addresses. So such a simplistic stack growth detector may get the wrong answer, but it's not undefined behavior: char stack_grows_up(uintptr_t callers_local) {
char my_local = (uintptr_t)&my_local > callers_local;
return my_local;
}
EDIT: Ah, and uintptr_t is an optional type. If the platform doesn't have it (e.g., because it's a segmented memory architecture) then this won't work, so it's not portable, but aside from that it's not undefined behavior, it's just that the computation of stack growth direction may well be wrong. |
|