View Single Post
Old 18 December 2019, 18:54   #9
Registered User

Join Date: Jun 2016
Location: europe
Posts: 183
It's still safe. In this case a temporary object will be constructed on stack but its scope is *not* limited to if's {} (it's limited to current function).
WORD* p_array = NULL;
WORD  x = 1, y = 2;
if (...) {
  p_array = { x, y };  // OK
if (...) {
  WORD a = 1, b = 2;
  p_array = { a, b };  // bad, a and b are limited to if's {}
The second case will still work though, because a temporary object on stack is valid and containts valid data because data type is WORD and is entirely copied into the object, and not something more complex (that includes pointers or references) that would cause dangling pointers/references. But it's bad and would be called out by compiler (but if you can get past that it should work).
a/b is offline  
Page generated in 0.04488 seconds with 11 queries