Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Anything cut to length will be too short.


devel / comp.lang.c / Re: How typedef works?

SubjectAuthor
* How typedef works?Thiago Adams
+* Re: How typedef works?Bart
|`* Re: How typedef works?Thiago Adams
| `* Re: How typedef works?Thiago Adams
|  +* Re: How typedef works?Bart
|  |`* Re: How typedef works?Thiago Adams
|  | `* Re: How typedef works?Ben Bacarisse
|  |  `* Re: How typedef works?Thiago Adams
|  |   +* Re: How typedef works?Stefan Ram
|  |   |`* Re: How typedef works?Stefan Ram
|  |   | `- Re: How typedef works?Stefan Ram
|  |   `* Re: How typedef works?Ben Bacarisse
|  |    `* Re: How typedef works?Thiago Adams
|  |     `* Re: How typedef works?Bart
|  |      `- Re: How typedef works?Thiago Adams
|  `- Re: How typedef works?Ben Bacarisse
+* Re: How typedef works?Ben Bacarisse
|`* Re: How typedef works?Thiago Adams
| +- Re: How typedef works?Thiago Adams
| +* Re: How typedef works?Bart
| |+* Re: How typedef works?Thiago Adams
| ||`* Re: How typedef works?Bart
| || `- Re: How typedef works?Bart
| |`* Re: How typedef works?Ben Bacarisse
| | `- Re: How typedef works?Bart
| `- Re: How typedef works?Ben Bacarisse
+* Re: How typedef works?Guillaume
|+* Re: How typedef works?Kaz Kylheku
||`- Re: How typedef works?Thiago Adams
|`- Re: How typedef works?Bonita Montero
`- Re: How typedef works?Stefan Ram

Pages:12
Re: How typedef works?

<87ilxo4otq.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18720&group=comp.lang.c#18720

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: Sat, 23 Oct 2021 00:33:37 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <87ilxo4otq.fsf@bsb.me.uk>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<sku9rq$muk$1@dont-email.me>
<009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>
<21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com>
<skuc62$tce$1@dont-email.me>
<72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com>
<87o87g4ua4.fsf@bsb.me.uk>
<27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="ed20cecd0609d32632257e4298dc9793";
logging-data="1194"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BkNGId3cMe7vliSVZj/jl1lzMIvW1+WA="
Cancel-Lock: sha1:LVhLAhMkgqDVHSAWGUyGn5Nu0cw=
sha1:uw+nsgJtWvqtI8LqD+CJQuXi5aA=
X-BSB-Auth: 1.254698d9f104b7b851c2.20211023003337BST.87ilxo4otq.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 22 Oct 2021 23:33 UTC

Thiago Adams <thiago.adams@gmail.com> writes:

> On Friday, October 22, 2021 at 6:36:00 PM UTC-3, Ben Bacarisse wrote:
>> Thiago Adams <thiago...@gmail.com> writes:
>>
>> > The problem is to join typedefs of typedefs ...
>> > like:
>> > typedef char* const T1[5];
>> > typedef const T1 *T2[2];
>> >
>> > I want the type of T2 "expanded" with no typedefs to be able to
>> > compare types.
>> For C++ (which has typeid) both of these should work because neither has
>> a top-level const qualification.
>>
>> This is a bad topic for comp.lang.c because you seem to be working in
>> C++ and the two languages are patricularly far apart on this topic.
>
> The question is not about C++ typedid etc..

It appeared to be, since you posted C++ that included <typeinfo>! I got
the wrong end of the stick.

> It is about how to "expand" the type T3 (for instance) to a type
> without typedefs or in other words expand to the equivalent type or
> real type.

The word "expand" in quotes is a bit vague. You don't want code that
prints any types, you just want to be know (maybe by using an informal
algorithm) how to write a type defined with one or more typedefs without
any typedefs. Is that what you mean?

> typedef void* (*T1)(char, char);
> typedef const T1 (*T2)(double);
> typedef volatile T2 (*T3)[3];
>
> I was using gcc/c++ facilities just to print the type. (In the middle of test
> const behavior - my mistake - added some noise to the topic.) A derived topic
> was the const behavior with _Generic as well.

Ah, I thought you wanted code to "expand" the type into a text string.

--
Ben.

Re: How typedef works?

<cdecl-20211023003329@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18721&group=comp.lang.c#18721

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: 22 Oct 2021 23:35:48 GMT
Organization: Stefan Ram
Lines: 54
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <cdecl-20211023003329@ram.dialup.fu-berlin.de>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com> <sku9rq$muk$1@dont-email.me> <009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com> <21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com> <skuc62$tce$1@dont-email.me> <72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com> <87o87g4ua4.fsf@bsb.me.uk> <27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com> <type-20211023000414@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de GcCh/97wGVF04c3AnL06iwqDM1PsRN09Y3oKU4jlMORoEo
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Fri, 22 Oct 2021 23:35 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>how to "expand" the type T3 (for instance) to a type without typedefs
>One can omit the "const" on the return type, so it's
>void * (* (* volatile (*)[3])(double))(char, char).

Here is the procedure:

typedef volatile T2 (*T3)[3]

means:

T3 = a pointer to an array of three volatile T2. (1)

and

typedef T1 (*T2)(double)

means:

T2 = a pointer to a function of double returning T1. (a)

Now, insert (a) into (1) to obtain:

T3 = a pointer to an array of three volatile
pointers to a function of double returning T1. (2)

Or,

typedef T1( *volatile( *T3a )[ 3 ])( double );

Next, step:

typedef void* (*T1)(char, char)

T1 = a pointer to a function of two chars yielding a void*. (b)

Now, insert the definition (b) into the (2) to obtain:

T3 = a pointer to an array of three volatile
pointers to a function of double returning
a pointer to a function of two chars yielding a void*. (3)

Or,

typedef void * (* (* volatile (*T3)[3])(double))(char, char)

, which declares T3 to have the type

void * (* (* volatile (*)[3])(double))(char, char)

. The famous program cdecl also can help to understand such
issues.

Re: How typedef works?

<FAQ-20211023005227@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18722&group=comp.lang.c#18722

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: 22 Oct 2021 23:53:10 GMT
Organization: Stefan Ram
Lines: 14
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <FAQ-20211023005227@ram.dialup.fu-berlin.de>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com> <sku9rq$muk$1@dont-email.me> <009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com> <21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com> <skuc62$tce$1@dont-email.me> <72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com> <87o87g4ua4.fsf@bsb.me.uk> <27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com> <type-20211023000414@ram.dialup.fu-berlin.de> <cdecl-20211023003329@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 4/9geJSYO1pgXTbqlrilEACbYMHuK/+QtQ1R4JqNCuAPvd
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Fri, 22 Oct 2021 23:53 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>. The famous program cdecl also can help to understand such
>issues.

I assume that before posting you (Thiago) already have
checked the FAQ with sections like

|1.21: How do I construct and understand declarations of complicated
| types such as "array of N pointers to functions returning
| pointers to functions returning pointers to char"?

, so that's why I have not mentioned the FAQ!

Re: How typedef works?

<896ab070-c773-42b6-b7e4-fa6b83c81526n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18728&group=comp.lang.c#18728

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:7fd5:: with SMTP id b21mr6888524qtk.101.1635001078908;
Sat, 23 Oct 2021 07:57:58 -0700 (PDT)
X-Received: by 2002:a05:622a:15c7:: with SMTP id d7mr6926388qty.203.1635001078682;
Sat, 23 Oct 2021 07:57:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Oct 2021 07:57:58 -0700 (PDT)
In-Reply-To: <87ilxo4otq.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<sku9rq$muk$1@dont-email.me> <009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>
<21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com> <skuc62$tce$1@dont-email.me>
<72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com> <87o87g4ua4.fsf@bsb.me.uk>
<27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com> <87ilxo4otq.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <896ab070-c773-42b6-b7e4-fa6b83c81526n@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Sat, 23 Oct 2021 14:57:58 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Thiago Adams - Sat, 23 Oct 2021 14:57 UTC

On Friday, October 22, 2021 at 8:33:49 PM UTC-3, Ben Bacarisse wrote:
....
> > typedef void* (*T1)(char, char);
> > typedef const T1 (*T2)(double);
> > typedef volatile T2 (*T3)[3];
> >
> > I was using gcc/c++ facilities just to print the type. (In the middle of test
> > const behavior - my mistake - added some noise to the topic.) A derived topic
> > was the const behavior with _Generic as well.
> Ah, I thought you wanted code to "expand" the type into a text string.

I guess for text representation this algorithm works:
We want to know the type of T3.

Because T3 uses T2:
Remove specifiers from T3
volatile (*T3)[3];

Because T2 uses T1:
Remove specifiers from T2

const (*T2)(double);

Copy T3 into T2 type-name.
const (* volatile (*T3)[3] )(double);

Do not remove specifiers of T1 because they are not type-name

Copy T2 result into T1 type-name
void* (*T1)(char, char);

Result:
void* (*const (* volatile (*T3)[3] )(double))(char, char);

Re: How typedef works?

<sl1tpp$8ss$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18729&group=comp.lang.c#18729

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: Sat, 23 Oct 2021 22:11:05 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <sl1tpp$8ss$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<sku9rq$muk$1@dont-email.me>
<009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>
<21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com>
<skuc62$tce$1@dont-email.me>
<72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com>
<87o87g4ua4.fsf@bsb.me.uk>
<27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com>
<87ilxo4otq.fsf@bsb.me.uk>
<896ab070-c773-42b6-b7e4-fa6b83c81526n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Oct 2021 21:11:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1e86dde5be44ad674ae104cbdba1e811";
logging-data="9116"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192YeaeWrhtsFAzyN5S86YDUY5EpVxHAhY="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:YEpGeywv7kQqB+1KyhgHcEkSgiM=
In-Reply-To: <896ab070-c773-42b6-b7e4-fa6b83c81526n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211023-4, 23/10/2021), Outbound message
 by: Bart - Sat, 23 Oct 2021 21:11 UTC

On 23/10/2021 15:57, Thiago Adams wrote:
> On Friday, October 22, 2021 at 8:33:49 PM UTC-3, Ben Bacarisse wrote:
> ...
>>> typedef void* (*T1)(char, char);
>>> typedef const T1 (*T2)(double);
>>> typedef volatile T2 (*T3)[3];
>>>
>>> I was using gcc/c++ facilities just to print the type. (In the middle of test
>>> const behavior - my mistake - added some noise to the topic.) A derived topic
>>> was the const behavior with _Generic as well.
>> Ah, I thought you wanted code to "expand" the type into a text string.
>
> I guess for text representation this algorithm works:
> We want to know the type of T3.
>
> Because T3 uses T2:
> Remove specifiers from T3
> volatile (*T3)[3];
>
> Because T2 uses T1:
> Remove specifiers from T2
>
> const (*T2)(double);
>
> Copy T3 into T2 type-name.
> const (* volatile (*T3)[3] )(double);
>
> Do not remove specifiers of T1 because they are not type-name
>
> Copy T2 result into T1 type-name
> void* (*T1)(char, char);
>
> Result:
> void* (*const (* volatile (*T3)[3] )(double))(char, char);
>

I couldn't follow that at all.

However, are you using a proper parser, or is this all done with
text-processing?

Because any typedef statement can have multiple T2s (as struct tags,
struct fields, parameter names, as well as a typedef).

I would assume you are since it would be impossible otherwise. But if
so, the issue with flattening typedefs is puzzling.

Given an internal, structured representation of a C type, the algorithm
you want is one for recreating the type as text in C syntax.

The process of parsing the typedefs should already have elimated any
embedded typedefs, so that by the time you get to T3, the representation
of its type should not mention T1 or T2.

Re: How typedef works?

<98e1c13c-02aa-4433-b83c-5a55d577ca8dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18731&group=comp.lang.c#18731

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:1c86:: with SMTP id ib6mr6272701qvb.26.1635041333512;
Sat, 23 Oct 2021 19:08:53 -0700 (PDT)
X-Received: by 2002:a37:a212:: with SMTP id l18mr7270756qke.28.1635041333293;
Sat, 23 Oct 2021 19:08:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Oct 2021 19:08:53 -0700 (PDT)
In-Reply-To: <sl1tpp$8ss$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<sku9rq$muk$1@dont-email.me> <009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>
<21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com> <skuc62$tce$1@dont-email.me>
<72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com> <87o87g4ua4.fsf@bsb.me.uk>
<27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com> <87ilxo4otq.fsf@bsb.me.uk>
<896ab070-c773-42b6-b7e4-fa6b83c81526n@googlegroups.com> <sl1tpp$8ss$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <98e1c13c-02aa-4433-b83c-5a55d577ca8dn@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Sun, 24 Oct 2021 02:08:53 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Thiago Adams - Sun, 24 Oct 2021 02:08 UTC

On Saturday, October 23, 2021 at 6:11:33 PM UTC-3, Bart wrote:
> On 23/10/2021 15:57, Thiago Adams wrote:
> > On Friday, October 22, 2021 at 8:33:49 PM UTC-3, Ben Bacarisse wrote:
> > ...
> >>> typedef void* (*T1)(char, char);
> >>> typedef const T1 (*T2)(double);
> >>> typedef volatile T2 (*T3)[3];
> >>>
> >>> I was using gcc/c++ facilities just to print the type. (In the middle of test
> >>> const behavior - my mistake - added some noise to the topic.) A derived topic
> >>> was the const behavior with _Generic as well.
> >> Ah, I thought you wanted code to "expand" the type into a text string.
> >
> > I guess for text representation this algorithm works:
> > We want to know the type of T3.
> >
> > Because T3 uses T2:
> > Remove specifiers from T3
> > volatile (*T3)[3];
> >
> > Because T2 uses T1:
> > Remove specifiers from T2
> >
> > const (*T2)(double);
> >
> > Copy T3 into T2 type-name.
> > const (* volatile (*T3)[3] )(double);
> >
> > Do not remove specifiers of T1 because they are not type-name
> >
> > Copy T2 result into T1 type-name
> > void* (*T1)(char, char);
> >
> > Result:
> > void* (*const (* volatile (*T3)[3] )(double))(char, char);
> >
> I couldn't follow that at all.
>
> However, are you using a proper parser, or is this all done with
> text-processing?

I have the parser , I have the ast.
I thought this textual algorithm would be more on topic here.


> Because any typedef statement can have multiple T2s (as struct tags,
> struct fields, parameter names, as well as a typedef).

yes. I represent types using the C "type-name" that consists
on declarator and list of specifiers qualifiers. This can represent the complex
declarations.
> I would assume you are since it would be impossible otherwise. But if
> so, the issue with flattening typedefs is puzzling.
>
> Given an internal, structured representation of a C type, the algorithm
> you want is one for recreating the type as text in C syntax.
> The process of parsing the typedefs should already have elimated any
> embedded typedefs, so that by the time you get to T3, the representation
> of its type should not mention T1 or T2.

Do you mean you remove dependent typedefs as soon as you parse?

My objective is add type checks in my compiler, checks arguments, return types,
etc. For this task I want to "normalize" the types so I can compare then using the
normalized version.

I need to create this algorithm to normalize typedefs depending on other typedefs
but this does not look so obvious.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor