Structure:

typedef struct some_struct { struct some_struct* p_next_link_self; // Где данный указатель // будет указывать на объект // который ссылается на него, // и в случае уничтожения текущего объекта, // цепочкой освободить все остальные объекты // далее идут поля и прочее } some_struct_t; 

Those. supposedly implementing a half-chained connection, where the structures will know who refers to them, and release the whole thing in the reverse order or if it can be called branching dependencies.

  • 2
    Yes, good. The usual singly-linked list is used in almost every program. - freim
  • it is even difficult to assume that it can be embarrassing here =) - Fat-Zer
  • @freim: For a "single-valued list", the pointer would have to be declared as struct some_struct * . - AnT
  • @ LENN: The type of struct some_struct_t not declared at all. What kind of chain connection are we talking about? How does struct some_struct_t relate to struct some_struct ? Be careful when drafting a question. Your code contains typos that make the whole question meaningless. - AnT
  • one
    @AnT: Well, do you immediately attack a person?) I can not vouch with 100% certainty, but I'm still pretty sure that the TS understands it all and in fact the question is: “I thought out the structure in which each instance refers to the next. When destroying an object, I entail the destruction of all connected objects in a chain. Is such a normal implementation? ” - Kir_Antipov

1 answer 1

Everything is absolutely normal. Here is a quotation from the classics ("C programming language". Brian V. Kernigan, Dennis M. Ritchie):

Let us return to the description of the site, which is conveniently presented in the form of a structure with four components:

 struct tnode { /* узел дерева */ char *word; /* указатель на текст */ int count; /* число вхождений */ struct tnode *left; /* левый сын */ struct tnode *right;/* правый сын */ }; 

The given recursive definition of a node may seem risky, but it is correct. A structure cannot include itself, but

 struct tnode *left; 

declares left as a pointer to tnode , not tnode itself.