I’ve declared a struct as follows:
struct Hex
{
CGPoint center;
CGPoint points[6];
CGFloat width;
CGFloat sideLength;
};
I have a factory method that initializes a Hex and returns it, like so (contents of CGPointMake calls omitted for brevity):
struct Hex hex =
{
CGPointMake(..),
{
CGPointMake(..),
CGPointMake(..),
CGPointMake(..),
CGPointMake(..),
CGPointMake(..),
CGPointMake(..)
},
width,
S
};
return hex;
If I break at the return statement and inspect hex, I see that the first member – CGPoint center – is intact, but the array’s elements are all listed as “Out of scope”.
How can I build and return this struct such that its array member’s contents will persist?
This ‘out of scope’ is just talking about what the debugger display is automatically keeping track of, and is not the fault of your build (assuming you built with debug info).
Fortunately you can tell gdb to evaluate expressions.
For example, if you are at a point in the execution where ‘hex’ is visible, click on the GDB Prompt in the xcode debugger and type “print hex.points[0]” and it should give you the value.