Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #151249 > unrolled thread
| Started by | Johann Klammer <klammerj@NOSPAM.a1.net> |
|---|---|
| First post | 2020-04-09 13:58 +0200 |
| Last post | 2020-04-09 19:20 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.c
direct-declarator or direct-abstract-declarator? Johann Klammer <klammerj@NOSPAM.a1.net> - 2020-04-09 13:58 +0200
Re: direct-declarator or direct-abstract-declarator? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-09 06:52 -0700
Re: direct-declarator or direct-abstract-declarator? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-09 11:23 -0400
Re: direct-declarator or direct-abstract-declarator? Johann Klammer <klammerj@NOSPAM.a1.net> - 2020-04-09 19:20 +0200
| From | Johann Klammer <klammerj@NOSPAM.a1.net> |
|---|---|
| Date | 2020-04-09 13:58 +0200 |
| Subject | direct-declarator or direct-abstract-declarator? |
| Message-ID | <r6n2lg$tlg$1@gioia.aioe.org> |
the n2176 draft has on page 100 the following exmples: > typedef signed int t; ..and later.. > t f(t (t)); > long t; About the first line they say: a function f is declared with type “function returning signed int with one unnamed parameter with type pointer to function returning signed int with one unnamed parameter with type signed int ” so this segments into: declaration declaration-specifiers init-declarator-list[opt] type-specifier declaration-specifiers[opt] init-declarator-list[opt] typedef-name init-declarator typedef-name declarator typedef-name direct-declarator typedef-name identifier (parameter-type-list) typedef-name identifier (parameter-list) typedef-name identifier (parameter-declaration) *1 typedef-name identifier (declaration-specifiers declarator) typedef-name identifier (typedef-name direct-declarator) typedef-name identifier (typedef-name (declarator)) typedef-name identifier (typedef-name (identifier)) *2 or alternatively starting from *1 typedef-name identifier (declaration-specifiers abstract-declarator[opt]) typedef-name identifier (typedef-name pointer[opt] direct-abstract-declarator) typedef-name identifier (typedef-name (abstract-declarator)(parameter-type-list)) *3 *2 is wrong as the last one is a declarator which won't ever resolve to a type-specifer/typedef-name. *3 won't match because the there's no (*) before the parameter list. It might be made to match if the direct abstract declarator were allowed to consist of solely a parameter-type list. So how do I get to the typedef name 't' there towards the end with the grammar specified?
[toc] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2020-04-09 06:52 -0700 |
| Message-ID | <86h7xsn4vr.fsf@linuxsc.com> |
| In reply to | #151249 |
Johann Klammer <klammerj@NOSPAM.a1.net> writes:
> [considering this code, excerpted from n2176, page 100:]
>
> typedef signed int t;
> t f(t (t));
>
> [About the declaration of f it is said:]
> a function f is declared with type
> "function returning signed int
> with one unnamed parameter
> with type pointer to function returning signed int
> with one unnamed parameter with type signed int"
>
> [...]
>
> So how do I get to the typedef name 't' there towards the end
> with the grammar specified?
t f( t ( t ) );
^ ^ ^ ^ ^
+ direct-abstract-declarator{opt} + + parameter-type-list + |
| |
| |
+------------- direct-abstract-declarator -----------------+
Does this help clarify things?
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2020-04-09 11:23 -0400 |
| Message-ID | <r6nelt$j8n$1@dont-email.me> |
| In reply to | #151249 |
On 4/9/20 7:58 AM, Johann Klammer wrote:
> the n2176 draft
> has on page 100 the following exmples:
>
>> typedef signed int t;
>
> ..and later..
>
>> t f(t (t));
>> long t;
>
> About the first line they say: a function f is declared with type �function returning signed int with one unnamed parameter with type pointer
> to function returning signed int with one unnamed parameter with type signed int �
>
> so this segments into:
> declaration
> declaration-specifiers init-declarator-list[opt]
> type-specifier declaration-specifiers[opt] init-declarator-list[opt]
> typedef-name init-declarator
> typedef-name declarator
> typedef-name direct-declarator
> typedef-name identifier (parameter-type-list)
> typedef-name identifier (parameter-list)
> typedef-name identifier (parameter-declaration) *1
...
> typedef-name identifier (declaration-specifiers abstract-declarator[opt])
> typedef-name identifier (typedef-name pointer[opt] direct-abstract-declarator)
The next steps are
typedef-name identifier (typedef-name direct-abstract-declarator[opt] (
parameter-typelist ) )
typedef-name identifier (typedef-name ( parameter-list ) )
typedef-name identifier (typedef-name ( parameter-declaration ) )
typedef-name identifier (typedef-name ( declaration-specifiers ) )
typedef-name identifier (typedef-name ( type-specifier ) )
typedef-name identifier (typedef-name ( typedef-name ) )
...
> It might be made to match if the direct abstract declarator were allowed to consist of solely
> a parameter-type list.
A direct-abstract-declarator IS allowed to consist solely of a
parenthesized parameter type list. See the last grammar production under
6.7.7p1. The above declaration is equivalent to
t f(t g(t h));
"A declaration of a parameter as ‘‘function returning type’’ shall be
adjusted to ‘‘pointer to function returning type’’, as in 6.3.2.1"
(6.7.6.3p8). Therefore, that declaration would be adjusted to
t f(t (*g)(t h));
This is directly analogous to the more familiar "A declaration of a
parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer
to type’’...". Thus, for example:
func( int callback(double), char array[20]);
is adjusted to
func( int (*callback)(double), char *array);
[toc] | [prev] | [next] | [standalone]
| From | Johann Klammer <klammerj@NOSPAM.a1.net> |
|---|---|
| Date | 2020-04-09 19:20 +0200 |
| Message-ID | <r6nlgq$19fi$1@gioia.aioe.org> |
| In reply to | #151264 |
On 04/09/2020 05:23 PM, James Kuyper wrote:
> A direct-abstract-declarator IS allowed to consist solely of a
> parenthesized parameter type list. See the last grammar production under
> 6.7.7p1. The above declaration is equivalent to
>
> t f(t g(t h));
Ah, thank you. I missed an opt there.
My real problem seems to be that the other interpretation as
declarator is valid if I can not use a rule wot says identifier-not-typedef-name.
But due to one of the preceding examples(on p99):
typedef signed int t;
typedef int plain;
struct tag {
unsigned t:4;
const t:5;
plain r:5;
};
namely the "const t:5;"
where the t has to be a typedef-name
I can not do this. They use the same declarator
production in there.. tho maybe it's not the same exactly.
Will try to write separate ones for struct/union and otherwise.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web