[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] XaAES modifications and clarification



Kåre Andersen a écrit :
struct remember_alloc; // ???
struct remember_alloc
{
       struct remember_alloc *next;
       void *addr;
};

what is happening here, why the double declaration (see: ???)

Not a double declaration; The "empty" statement is a declaration, the
second is a definition. A declaration (or "forward declaration") lets
the compiler know that there is code for a symbol like this somewhere
(same source file or other linked in file). Often you find them at the
top of the source while the definition follows in the code "body"
somewhere - and has the actual function.

This is the basic pattern for a linked list.
It uses a recursive structure.

The compiler consider a structure as defined after the closing brace. So without a special artifice, a structure member can't refer to itself, because the type has not been defined yet.

A forward declaration is not enough to declare a variable using the type of the struct, but it is enough to declare a pointer to it.
So this does the trick.

--
Vincent Rivière