Reputation: 329
I have some code I can't quite understand.
typedef double Align;
union header{
struct{
union header *ptr;
unsigned int size;
}s;
Align x;
};
typedef union header Header;
So, after creating this union it's used in a wierd way.
Header *morecore(unsigned);
This is then called like a normal function
Header *p;
p = morecore(nunits);
How exactly does this work? There is no code anywhere telling how this "function" works.
Upvotes: 2
Views: 78
Reputation: 7472
Header *morecore(unsigned);
is a forward declaration of a function named morecore
which takes 1 parameter of type unsigned
and returns a pointer to Header
. It is not related to the way how Header was defined. This function is defined somewhere in your code together with its body.
Upvotes: 1
Reputation: 19864
Header *morecore(unsigned);
This function returns a pointer of type Header
. So the return value is assigned to the same type which is
Header *p = morecore(nunits);
So basically the function morecore()
internally does some operation and returns a pointer and this return value is assigned to p
.
Upvotes: 3