How does a C compiler (I'm using GCC) know what to do with the following?
struct node
{
int x;
struct node* next;
};
More precisely, if node
has yet to be completely defined yet (we have not reached the closing curly brace), then how does the compiler know how big a struct ought to be?
While I realize that "pointing to" only requires an address, incrementing pointers does require the size of the data it points to.
Self Referential structures are those structures that have one or more pointers which point to the same type of structure, as their member. In other words, structures pointing to the same type of structures are self-referential in nature.
The self-referential structure is a structure that points to the same type of structure. It contains one or more pointers that ultimately point to the same structure. Structures are a user-defined data structure type in C and C++.
A self-referential structure is a structure that can have members which point to a structure variable of the same type. They can have one or more pointers pointing to the same type of structure as their member.
In many object-oriented programming languages, this (also called self or Me ) is a variable that is used in instance methods to refer to the object on which they are working. The first OO language, SIMULA 67, used this to explicitly reference the local object.
The size of the struct
is not important, as a pointer to the struct
is being stored, not the struct
itself.
In terms of incrementing pointers to struct
; that is done outside of the struct
definition, so again, is not important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With