Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #59416

Re: struct tag (*[5])(float)

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: struct tag (*[5])(float)
Date 2015-04-01 19:29 -0400
Organization Self
Message-ID <551C7F62.50701@verizon.net> (permalink)
References <mfhjtf$plc$1@dont-email.me> <551C65E3.8010903@verizon.net> <mfhpfk$g36$1@dont-email.me> <cotohattrq2loq8eqvj757qiuhkaorga1s@4ax.com>

Show all headers | View raw


On 04/01/2015 07:01 PM, Barry Schwarz wrote:
> On Wed, 01 Apr 2015 22:55:50 +0100, Bartc <bc@freeuk.com> wrote:
> 
>> On 01/04/2015 22:40, James Kuyper wrote:
...
>>> What you are talking about is described in 6.7.7p2:
>>> "In several contexts, it is necessary to specify a type. This is
>>> accomplished using a _type name_, which is syntactically a declaration
>>> for a function or an object of that type that omits the identifier.".
>>> I'm using underscores to mark the fact that "type name" is in italics, a
>>> convention used in ISO standards to indicate that the clause it appears
>>> in is, officially, the definition for the italicized term.
>>>
>>> Whenever a type name is allowed, if the code that you're parsing matches
>>> one of the grammar productions in 6.7.7p1, then it is a type name. Since
>>> and identifier qualifies as a direct-declarator (6.7.6p1), but does NOT
>>> qualify as a direct-abstract-declarator (6.7.7p1), in order to match
>>> those grammar rules, you must sooner or later parse it down to the point
>>> where an optional abstract-declarator or direct-abstract-declarator is
>>> missing - and that's precisely where the missing identifier would go.
>>> Insert an arbitrary dummy identifier in that location, and the type name
>>> should make sense as a declaration.
>>>
>>> The examples given in 6.7p3 might help clarify this issue.
>>
>> But is a human reader supposed to do keep all this in mind? It should be 
>> instantly obvious!

For me, it usually is - but I've been programming in C since around 1980.

>> I know there is an informal algorithm that can be used (and that people 
>> used to keep posting whenever I complained about complex typespecs), but 
>> I could never get it and just resorted to Cdecl instead. However the 
>> online Cdecl I used is no longer available, and I have to use trial and 
>> error.

Offhand, I can't figure out what algorithm I'm actually using. An
algorithm that works is to insert a dummy identifier in the first
location where the insertion would turn the type name into a valid
declaration for that identifier. If there is no such location, it isn't
a valid type name. If that identifier would identify an inline or
_Noreturn function, or an object with an alignment specification or an
initializer, then it isn't a valid type name. Otherwise, the type name
names the type that the identifier would have, if it were a declaration.

However, that algorithm requires a great deal of familiarity with C
declaration syntax - which is something that I have, but which Bartc and
most entry-level C programmers don't have.

While researching my answers for this thread, I noticed that 6.7.4p2
prohibits

	void _Noreturn (*noreturn_function)(void);

I was rather surprised by that - I would have thought that would be a
useful thing to allow.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

struct tag (*[5])(float) "James Harris" <james.harris.1@gmail.com> - 2015-04-01 21:17 +0100
  Re: struct tag (*[5])(float) James Kuyper <jameskuyper@verizon.net> - 2015-04-01 17:40 -0400
    Re: struct tag (*[5])(float) Bartc <bc@freeuk.com> - 2015-04-01 22:55 +0100
      Re: struct tag (*[5])(float) Barry Schwarz <schwarzb@dqel.com> - 2015-04-01 16:01 -0700
        Re: struct tag (*[5])(float) James Kuyper <jameskuyper@verizon.net> - 2015-04-01 19:29 -0400
          Re: struct tag (*[5])(float) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-02 05:28 -0700
        Re: struct tag (*[5])(float) Bartc <bc@freeuk.com> - 2015-04-02 00:37 +0100
      Re: struct tag (*[5])(float) Keith Thompson <kst-u@mib.org> - 2015-04-01 20:13 -0700
        Re: struct tag (*[5])(float) Bartc <bc@freeuk.com> - 2015-04-02 10:30 +0100
          Re: struct tag (*[5])(float) Keith Thompson <kst-u@mib.org> - 2015-04-02 15:18 -0700
  Re: struct tag (*[5])(float) John Bode <jfbode1029@gmail.com> - 2015-04-02 15:22 -0700

csiph-web