1

私はこのtypedefを次のような構造体に使用しました

typedef struct { double x, y; } ACVector;

デバッガーでこのインスタンスを見ると、次のような非常に奇妙な出力が得られます。

(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

ACVectorの定義をに変更した場合

typedef struct ACVector { double x, y; } ACVector;

デバッガーでも同じことをします。期待どおりの結果が得られます。

(lldb) p _translation
(ACVector) $1 = {
  (double) x = -5503.61
  (double) y = -1315.67
}

typedefに匿名構造体を使用することは合法です

OK、もっとコード

_translationの宣言はインスタンス変数として行われます

ACVector    _translation;

この関数を使用して変数を初期化します

ACVector ACVectorMake( double x, double y )
{
    ACVector    r;
    r.x = x;
    r.y = y;
    return r;
}

このような

_translation = ACVectorMake( d[xp[0]].x-s[xp[0]].x,  d[xp[0]].y-s[xp[0]].y );

もともとは

ACVector ACVectorMake( double x, double y )
{
    return (ACVector){x,y};
}

また、デバッガーの出力で緯度と経度の要素はどこから取得されますか。個別にアクセスすることはできません。

他の場所で定義されたACVectorに対応する詳細情報

私には2つの定義があります

#define ACVectorZero        (ACVector){(double)0.0,(double)0.0}
#define ACVectorUnit        (ACVector){(double)1.0,(double)1.0}

興味深いことに、これに直接続く

#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 )}

これはおそらくACVectorの緯度と経度の発生を説明することができます

ライブラリを含むACVectorのすべてのオカレンスを検索しましたが、定義されているACVectorの他のオカレンスを見つけることができませんでした

これはすべてXcode4.5ゴールドマスターを使用しています

4

2 に答える 2

0

私の賭けは、おそらく変数の宣言のstruct ACVector _translation代わりに使用することです。ACVector _translation

より多くのコードを見せてください。

于 2012-09-19T12:05:41.317 に答える
0

によると

C言語規格n1256

6.7.4 関数指定子の下

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. 

たとえば、これにより new_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;
}

そうです、今私たちは言うことができます

typedef に無名構造体を使用することは合法です

だから今、あなたは予期しない行動を起こす何か他のことをしています..

于 2012-09-19T12:17:05.603 に答える