vendredi 8 mai 2015

typedef struct name name without a subsequent struct definition

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?

Aucun commentaire:

Enregistrer un commentaire