I found the following code at lines 153-154 in the libelf.h of the libelf library:
/* Descriptor for the ELF file. */
typedef struct Elf Elf;
I was looking for a struct definition of Elf but did not find it.
Later in the code, Elf is used, e.g.
/* Return descriptor for ELF file to work according to CMD. */
extern Elf *elf_begin (int __fildes, Elf_Cmd __cmd, Elf *__ref);
In the thread Why should we typedef a struct so often in C?, user "unwind" says:
Also note that while your example (and mine) omitted naming the
structitself, actually naming it is also useful for when you want to provide an > opaque type. Then you'd have code like this in the header, for instance:
typedef struct Point Point;
Point * point_new(int x, int y);and then provide the
structdeclaration in the implementation file.
Yet, I couldnt find a definition of the struct Elf in any c file either.
What am I missing? What is the purpose of a typedef struct Name_xy Name_xy; without struct definition? Or is this impossible and I just did not find the struct definition?
Edit:
First, thank you for the numerous great replies. As my question was two-fold (at least), there are two answers:
- I did not find the definition because I did not have the
lib/private.hfile (thanks @molbdnilo to point out that the definition is in there). I installed the sources ofelfutilsand not oflibelf. It seems that theprivate.his not included in theelfutilssource package. - The answers from @Acrasidae, @sfjac, and @Matt McNabb explain the conceptual background (opaque type, encapsulation, minimising dependencies ...).