Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下の構造体定義について混乱しています。どちらも正解ではないでしょうか?Borland C では両方がコンパイルされますが、gcc では 2 番目のみがコンパイルされます。エラーは「不明な型名_Node」です。
_Node
typedef struct _Node { int item; _Node* next; } Node; typedef struct _Node { int item; struct _Node* next; } Node;
コンパイラが前方参照を処理する方法によって異なります。gcc コンパイラは C++ コンパイラでもあるため、デフォルトでこれを実行できます。
いいえ、C では 2 番目 (明示的にstruct指定子を含む) のみが正しいです。C++ では を省略できますがstruct、c では省略できないため、これは移植性のない Borland 拡張機能です。g++ でコンパイルする場合、最初の構文も受け入れる必要があると思います。
struct