4 ms·
For the first example, for C or C++ code gcc will catch the dangling reference/pointer and warn about it, and since my group normally turns on -Wall -Werror, it
by not2b 2y ago
For the first example, for C or C++ code gcc will catch the dangling reference/pointer and warn about it, and since my group normally turns on -Wall -Werror, it's an error. However, the analysis is local and not as powerful as Rust's borrow checker.
Try
int* bug() {
int longlived = 12;
int* plonglived = &longlived;
{
int shortlived = 13;
plonglived = &shortlived;
}
return plonglived;
}
With gcc -Wall -Werror