A
とA
の定義があります。2 struct
があります。私はstruct A
にPOINTERが含まれているが、構造体の定義は、閉じ中括弧まで終了していないのでstruct A
ががstruct A
(ないポインタ)"struct inside struct"の制限
答えて
が含まれていることができない理由を私は理解していないstruct A
にOKがあることを知っています}
。構造体メンバを宣言するためには、コンパイラは完全な定義を必要とします。その情報を使用してスペースやパディング、アラインメントなどを計算する必要があります。ポインタのサイズはポインタのサイズであり、タイプの名前であり、完全な定義ではありません。それは再帰的に独自のタイプのデータメンバーを格納しなければならないように、その場合には、それは無限のストレージを取るため
struct A // Here the compiler knows that there is a structure named A
// The compiler does not know its contents, nor its size
{
// Some members...
struct A *pointer_to_a; // All the compiler needs to know is the symbol A
// The size and alignment is that of a pointer
// and those are known by the compiler
// Some more members...
// struct A instance_of_A; // This is not possible! At this point the
// compiler doesn't have the full definition
// of the structure, and can therefore not
// know how much space it need to allocate
// for the member
// Some even more members...
}
// Now the compiler knows the full contents of the structure, its size
// and alignment requirements
;
:
は、例えば、単純な構造を取ることができます。だから、それは不可能です。一方、ポインタのサイズは固定されているため、問題はありません。
だが、それは、独自の型のオブジェクトを含めることができたとしましょう:
struct A_
{
A_ a;
int b;
} A;
sizeof(A)
何?回答:sizeof(A)+sizeof(int)
:不可能です。
構造体を内部に配置すると、構造体の別のコピーがその時点で構造体に配置されます。たとえば:
struct A {
int q;
int w;
};
struct B {
int x;
struct A y;
int z;
};
これは、このようにメモリにレイアウトされます。
int /*B.*/x;
int /*A.*/q;
int /*A.*/w;
int /*B.*/z;
しかし、あなたが自分自身の内側に構造体を配置しようとします
struct A {
int x;
struct A y;
};
あなたはAを持っています、これはintともう一つのAを含み、もう一つのAはintともう一つのAを含んでいます。そして、あなたはintの無限の数を持っています。
これといくつかの矛盾が修正されました。ありがとうございます。 – Mike
- 1. struct in struct in struct
- 2. struct with struct with struct
- 3. struct
- 4. structのstructにアクセスする方法
- 5. struct c#
- 6. typedef structのメモリリーク
- 7. スウィフトのStruct
- 8. このStructタイプ
- 9. C#のStructジェネリックコンストラクタ
- 10. python structを使用してstructにstructをパックする方法は?
- 11. ColdFusion StructとAjax
- 12. json to C++ struct
- 13. char * ptr to struct
- 14. bson.M to struct
- 15. struct in Golang
- 16. Python Struct/Packing errors
- 17. は 'struct tm&
- 18. Const struct in Go
- 19. struct element manipulation(matlab)
- 20. Swift AppDelegate Struct usage
- 21. AVX float4/double4 struct
- 22. shm_memory + mmap + table + struct
- 23. python:c-structとwintypes
- 24. structには
- 25. タイプ 'struct s_action(*)
- 26. Xcode C++ Struct Order
- 27. ローカルのstruct in c
- 28. Goのnew(Struct)と&Struct {}の違いは何ですか?
- 29. structとstructの型をtypedefするのはいつですか?
- 30. バイナリ式のオペランドが無効です( 'struct node'と 'struct node')
私はこの質問に行くでしょう - おそらく手に入れる辞書を持っています –
あなたの質問をよく理解しないでください –
[struct inside struct]の可能な複製(http://stackoverflow.com/questions/14040612/) struct-inside-struct) – Olaf