git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Forward declaration of enum iterator_selection?

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
Aug 8, 2016, 18:52 UTC
Message-ID
<53ab8626-f862-a732-b369-abeab69a468f@ramsayjones.plus.com>
In-Reply-To
<c1ef8a65-844f-b676-cae0-abba87930063@ramsayjones.plus.com>
On 08/08/16 19:28, Ramsay Jones wrote:
Show 28 quoted lines
> 
> 
> On 08/08/16 17:30, Johannes Sixt wrote:
>> Am 07.08.2016 um 22:34 schrieb Ramsay Jones:
>>> On 05/08/16 23:26, Johannes Sixt wrote:
> [snip]
>>> 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 https://gcc.gnu.org/onlinedocs/gcc/Incomplete-Enums.html which indicates that this is a GCC extension.
> 
> Ah, well spotted!
> 
> You prompted me to look at the C99 (and C11) standards, in particular
> sections 6.7.2.2 (Enumeration specifiers) and 6.7.2.3 (Tags).
> 
> So, while (technically) enumeration types are incomplete prior to the
> closing } in its definition, the constraint imposed in 6.7.2.3-2 states:
> 
> 	"A type specifier of the form
> 		enum identifier
> 	without an enumerator list shall only appear after
> 	the type it specifies is complete"
> 
> which pretty much rules out its use here.
BTW, you can make gcc be that 'pickier compiler' you mentioned, thus:
$ rm refs.o
$ make CFLAGS='-g -O2 -Wall -std=c99 -pedantic' refs.o
    * new build flags
    CC refs.o
In file included from refs.c:8:0:
refs/refs-internal.h:363:14: warning: ISO C forbids forward references to ‘enum’ types [-Wpedantic]
 typedef enum iterator_selection ref_iterator_select_fn(
              ^
$ 
:-D

ATB, Ramsay Jones

Previous: Ramsay JonesNext: Michael Haggerty
Message 5 of 6 in “Forward declaration of enum iterator_selection?”
  1. Johannes SixtAug 5, 2016
  2. Ramsay JonesAug 7, 2016
  3. Johannes SixtAug 8, 2016
  4. Ramsay JonesAug 8, 2016
  5. Ramsay JonesAug 8, 2016
  6. Michael HaggertyAug 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.