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
struct
itself, 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
struct
declaration 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.h
file (thanks @molbdnilo to point out that the definition is in there). I installed the sources ofelfutils
and not oflibelf
. It seems that theprivate.h
is not included in theelfutils
source package. - The answers from @Acrasidae, @sfjac, and @Matt McNabb explain the conceptual background (opaque type, encapsulation, minimising dependencies ...).