In C, unlike C ++, there is no such built-in type as bool . There is a built-in _Bool integer type, which takes two values: 1 and 0.
However, you can include the <stdbool.h> header in the program, which defines the macro bool , which expands as _Bool .
From standard C (6.2.5 Types):
2 An object is declared as the type 0 and 1.
and (7.18 Boolean type and values)
2 The macro
bool
expands to _Bool.
In this ad
typedef bool list_less_func (const struct list_elem *a, const struct list_elem *b, void *aux);
which is equivalent to an ad
typedef _Bool list_less_func (const struct list_elem *a, const struct list_elem *b, void *aux);
if you remove the typedef keyword
bool list_less_func (const struct list_elem *a, const struct list_elem *b, void *aux);
then we simply get a function declaration with the name list_less_func .
So, this typedef introduces the symbolic name list_less_func for the type of the function, and not for the name bool , which, as I wrote, is defined in the heading <stdbool.h> , that is, for the type of function
bool (const struct list_elem *a, const struct list_elem *b, void *aux);
which has three parameters and the return value is bool .
This allows the declaration of the list_insert_ordered function list_insert_ordered concisely specify the type of the third parameter.
void list_insert_ordered (struct list *list, struct list_elem *elem, list_less_func *less, void *aux);
as list_less_func * .
Otherwise, without a typedef, you would have to write a very long declaration of the third parameter in the declaration of the list_insert_ordered function, for example,
void list_insert_ordered (struct list *list, struct list_elem *elem, bool less (const struct list_elem *, const struct list_elem , void *), void *aux);
or how
void list_insert_ordered (struct list *list, struct list_elem *elem, bool ( *less )(const struct list_elem *, const struct list_elem *, void *), void *aux);
That, you see, makes the declaration of the list_insert_ordered function difficult to read.
return list_insert (e, elem);inside a function that returnsvoid. Iflist_insertitself returnsvoid, then such code would be valid in C ++. But in C is never allowed. - AnT