-1

次のコードを検討してください。

struct blah {
    int x;
    int y;
};

struct foo {
    union {
        struct {
            struct blah *b;
        };
    };
};

int main()
{
    struct foo f;
    struct blah *b;

    // Warning on below assignment
    b = &f.b;
    return 0;
}

assignment from incompatible pointer typeLHS と RHS の両方が同じタイプ (明らかに) であるにもかかわらず、GCC が警告を生成するのはなぜですか? struct blahIOW、がネストされていると何が変わるのstruct fooですか?

ここに有効な警告がある場合、それは何ですか?

4

2 に答える 2

3

b = &f.b;に を割り当てようとblah**bます。b = f.b;代わりに使用

于 2012-12-20T09:55:11.003 に答える
1
struct blah {
    int x;
    int y;
};

struct foo {
    union {
        struct {
            struct blah b;
        };
    };
};

あなたbはすでにポインタである参照しています。

于 2012-12-20T09:58:15.163 に答える