Reputation: 6047
I had this typedef for a struct like
typedef struct { double x, y; } ACVector;
and when I look at instances of this in the debugger I get very strange output something like
(lldb) p _translation
(ACVector) $1 = {
(double) x = -5503.61
(double) y = -5503.61
(CLLocationDegrees) latitude = -5503.61
(CLLocationDegrees) longitude = -1315.67
}
(lldb) p _translation.x
(double) $2 = -5503.61
(lldb) p _translation.y
(double) $2 = -5503.61
if I change the definition of ACVector to
typedef struct ACVector { double x, y; } ACVector;
and do the same in the debugger I get what I expect
(lldb) p _translation
(ACVector) $1 = {
(double) x = -5503.61
(double) y = -1315.67
}
It is legal to use anonymous structs for typedef
the declaration of _translation is as an instance variable
ACVector _translation;
I use this function to initialise the variable
ACVector ACVectorMake( double x, double y )
{
ACVector r;
r.x = x;
r.y = y;
return r;
}
Like this
_translation = ACVectorMake( d[xp[0]].x-s[xp[0]].x, d[xp[0]].y-s[xp[0]].y );
Originally it was a
ACVector ACVectorMake( double x, double y )
{
return (ACVector){x,y};
}
And where would the latitude and longitude elements come from in the debugger output, mind you you could not access them individually
I have two defines
#define ACVectorZero (ACVector){(double)0.0,(double)0.0}
#define ACVectorUnit (ACVector){(double)1.0,(double)1.0}
which interestingly are followed directly by
#define ACDegreesFromDegreesMinutesSeconds( d, m, s ) (CLLocationDegrees)(d+m/60.0+s/3600.0)
#define ACLocationFromDegreesMinutesSeconds( yd, ym, ys, xd, xm, xs ) (CLLocationCoordinate2D){ACDegreesFromDegreesMinutesSeconds( xd, xm, xs ), ACDegreesFromDegreesMinutesSeconds( yd, ym, ys )}
which could explain perhaps explain the occurrence of latitude and longitude in ACVector
Did a search for every occurrence of ACVector including in libraries, couldn't find any other occurrences of ACVector being defined
Upvotes: 1
Views: 456
Reputation: 27240
According to
Under 6.7.4 Function specifiers
12
The one exception allows the value of a restricted pointer to be carried
out of the block in which it (or, more
precisely, the ordinary identifier used to designate it) is declared when
that block finishes execution.
For example, this permits new_vector to return a vector.
typedef struct { int n; float * restrict v; } vector;
vector new_vector(int n)
{
vector t;
t.n = n;
t.v = malloc(n * sizeof (float));
return t;
}
So yes now we can say
It is legal to use anonymous structs for typedef
So now you are doing something else which case unexpected behaviour for you..
Upvotes: 0
Reputation: 9200
My bet is that you probably use struct ACVector _translation
instead of ACVector _translation
in the declaration of your variable.
Please show us more code.
Upvotes: 0