Am 07.08.2016 um 22:34 schrieb Ramsay Jones:
On 05/08/16 23:26, Johannes Sixt wrote:
When refs.c is being compiled, the only mention of enum
iterator_selection is in this piece of code pulled in from
refs-internal.h(have a look at the preprocessed code):

typedef enum iterator_selection ref_iterator_select_fn(
         struct ref_iterator *iter0, struct ref_iterator *iter1,
         void *cb_data);

This looks like a forward declarations of an enumeration type name,
something that I thought is illegal in C. Am I wrong? (That may well be
the case, my C-foo is quite rusty.)

At this point 'enum iterator_selection' is an incomplete type and may
be used when the size of the object is not required. It is not needed,
for example, when a typedef name is being declared as a pointer to, or
as a function returning such a type. However, such a type must be
complete before such a function is called or defined.

All you say is true when it is a struct type, of course. But I doubt that there exists such a thing called "incomplete enumeration type" in C. In fact, with these keywords I found which indicates that this is a GCC extension.

[...] I would rather the 'enum iterator_selection' be defined
before this declaration. One solution could be to #include "iterator.h"
prior to _all_ #include "refs/refs-internal.h" in all compilation units
(Note it is in the opposite order in refs/iterator.c). Alternatively, you
could put the #include "../iterator.h" into refs/refs-internal.h directly
(some people would object to this).

I concur. Which one is the correct way to do, I do not know, either. It's a matter how the interface is intended to be used. Perhaps the typedef must be moved to iterator.h?

-- Hannes

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to