I used to think returning a reference is bad as our returned reference will refer to some garbage value. But this code works (matrix
is a class):
co
I see no buf
declared anywhere, which means it doesn't go out of scope with function return, so it's okay. (it actually looks like it's meant to be matrixbuf
which is also fine, because it's static
).
EDIT: Thanks to R. Martinho Fernandes for the guess. Of course it is matrix buf
, so it makes buf
static array in which temporary is allocated to make sure it doesn't get freed when the function returns and therefore the return value is still valid.