Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The best diplomat I know is a fully activated phaser bank. -- Scotty


devel / comp.lang.c / 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
How typedef works?

<b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5f54:: with SMTP id y20mr12459707qta.324.1634902696173;
Fri, 22 Oct 2021 04:38:16 -0700 (PDT)
X-Received: by 2002:a05:620a:448e:: with SMTP id x14mr9431269qkp.459.1634902695968;
Fri, 22 Oct 2021 04:38:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 04:38:15 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
Subject: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 11:38:16 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 46
 by: Thiago Adams - Fri, 22 Oct 2021 11:38 UTC

What is the final type when we use typed of typedef ... ?

I am trying to find out looking at samples. But what is the rule?

--- GCC ---

https://godbolt.org/z/fsMMzcqGz

#include <stdio.h>
#include <typeinfo>
#include <cxxabi.h>

int status;
#define TYPE(EXPR) \
printf("%s=", #EXPR); \
printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))

typedef char* T1;
typedef const T1 CONST_T1;
typedef CONST_T1 T2[5];
typedef T2 T3[2];

int main()
{ TYPE(T1);
TYPE(CONST_T1);
TYPE(T2);
TYPE(T3);
} -----
It prints:

T1=char*
CONST_T1=char*
T2=char* [5]
T3=char* [2][5]

Sometimes the const disappears, like CONST_T1.

changing to
typedef const char* CONST_T1;
then CONST_T1 prints
CONST_T1=char const*

Re: How typedef works?

<sku9rq$muk$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Oct 2021 13:12:30 +0100
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <sku9rq$muk$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Oct 2021 12:12:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e030f06cd8f6adad2f34518bd1ab2da";
logging-data="23508"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FNYdtbAmJa7rrh35tRQQenc+FTMF38jw="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:zR7UiBonwBe3N+ev1EXV1mORrZU=
In-Reply-To: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211022-0, 22/10/2021), Outbound message
 by: Bart - Fri, 22 Oct 2021 12:12 UTC

On 22/10/2021 12:38, Thiago Adams wrote:
>
> What is the final type when we use typed of typedef ... ?
>
> I am trying to find out looking at samples. But what is the rule?
>
> --- GCC ---
>
> https://godbolt.org/z/fsMMzcqGz
>
> #include <stdio.h>
> #include <typeinfo>
> #include <cxxabi.h>
>
> int status;
> #define TYPE(EXPR) \
> printf("%s=", #EXPR); \
> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
>
> typedef char* T1;
> typedef const T1 CONST_T1;
> typedef CONST_T1 T2[5];
> typedef T2 T3[2];
>
> int main()
> {
> TYPE(T1);
> TYPE(CONST_T1);
> TYPE(T2);
> TYPE(T3);
> }
> -----
> It prints:
>
> T1=char*
> CONST_T1=char*
> T2=char* [5]
> T3=char* [2][5]
>
> Sometimes the const disappears, like CONST_T1.
>
> changing to
> typedef const char* CONST_T1;
> then CONST_T1 prints
> CONST_T1=char const*

If I do this in my C compiler, which has the special directive $showtype:

typedef char* T1;
typedef const T1 CONST_T1;
typedef CONST_T1 T2[5];
typedef T2 T3[2];

$showtype T1;
$showtype const T1;
$showtype T2;
$showtype T3;

then when compiling, it shows (using Algol68-style LTR type syntax):

Type is: ref schar
Type is: const ref schar
Type is: [5]const ref schar
Type is: [2][5]const ref schar

This seems to be in accordance with what gcc reports for this code:

int main()
{
T2 a;
T3 b;

a[0]=0;
b[0][0]=0;
}

Both of those array elements are read-only.

Perhaps your cxxabi header doesn't work properly.

Re: How typedef works?

<009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:16c:: with SMTP id y12mr812016qvs.67.1634905157108;
Fri, 22 Oct 2021 05:19:17 -0700 (PDT)
X-Received: by 2002:ac8:5fcd:: with SMTP id k13mr12804008qta.226.1634905156862;
Fri, 22 Oct 2021 05:19:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 05:19:16 -0700 (PDT)
In-Reply-To: <sku9rq$muk$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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 12:19:17 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 79
 by: Thiago Adams - Fri, 22 Oct 2021 12:19 UTC

On Friday, October 22, 2021 at 9:12:54 AM UTC-3, Bart wrote:
> On 22/10/2021 12:38, Thiago Adams wrote:
> >
> > What is the final type when we use typed of typedef ... ?
> >
> > I am trying to find out looking at samples. But what is the rule?
> >
> > --- GCC ---
> >
> > https://godbolt.org/z/fsMMzcqGz
> >
> > #include <stdio.h>
> > #include <typeinfo>
> > #include <cxxabi.h>
> >
> > int status;
> > #define TYPE(EXPR) \
> > printf("%s=", #EXPR); \
> > printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
> >
> > typedef char* T1;
> > typedef const T1 CONST_T1;
> > typedef CONST_T1 T2[5];
> > typedef T2 T3[2];
> >
> > int main()
> > {
> > TYPE(T1);
> > TYPE(CONST_T1);
> > TYPE(T2);
> > TYPE(T3);
> > }
> > -----
> > It prints:
> >
> > T1=char*
> > CONST_T1=char*
> > T2=char* [5]
> > T3=char* [2][5]
> >
> > Sometimes the const disappears, like CONST_T1.
> >
> > changing to
> > typedef const char* CONST_T1;
> > then CONST_T1 prints
> > CONST_T1=char const*
> If I do this in my C compiler, which has the special directive $showtype:
> typedef char* T1;
> typedef const T1 CONST_T1;
> typedef CONST_T1 T2[5];
> typedef T2 T3[2];
> $showtype T1;
> $showtype const T1;
> $showtype T2;
> $showtype T3;
>
> then when compiling, it shows (using Algol68-style LTR type syntax):
>
> Type is: ref schar
> Type is: const ref schar
> Type is: [5]const ref schar
> Type is: [2][5]const ref schar
>
> This seems to be in accordance with what gcc reports for this code:
>
> int main()
> {
> T2 a;
> T3 b;
>
> a[0]=0;
> b[0][0]=0;
> }
>
> Both of those array elements are read-only.
>
> Perhaps your cxxabi header doesn't work properly.

Yes it is not printing correctly.
My question still the same but the sample can be ignored.

Re: How typedef works?

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

  copy mid

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

  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: Fri, 22 Oct 2021 13:38:54 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <87ee8d5j4x.fsf@bsb.me.uk>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a3bb1bc3dae98cca541349f73000b53d";
logging-data="30499"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2Bxl5n9UcrrybJCOoNph//eXdU7OvJiE="
Cancel-Lock: sha1:ytSJd41PochqMAkIPdYiusAJJnk=
sha1:uVCAvis9yvVBPZ5KZ3Zd5WnhCIk=
X-BSB-Auth: 1.556ca371535983fa45a3.20211022133854BST.87ee8d5j4x.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 22 Oct 2021 12:38 UTC

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

> #include <stdio.h>
> #include <typeinfo>
> #include <cxxabi.h>
>
> int status;
> #define TYPE(EXPR) \
> printf("%s=", #EXPR); \
> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
>
> typedef char* T1;
> typedef const T1 CONST_T1;
> typedef CONST_T1 T2[5];
> typedef T2 T3[2];
>
> int main()
> {
> TYPE(T1);
> TYPE(CONST_T1);
> TYPE(T2);
> TYPE(T3);
> }

This is C++ behaving as specified:

In all cases, top-level cv-qualifiers are ignored by typeid (that is,
typeid(const T) == typeid(T)).

https://en.cppreference.com/w/cpp/language/typeid

--
Ben.

Re: How typedef works?

<21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a0c:fa08:: with SMTP id q8mr794887qvn.19.1634906481265;
Fri, 22 Oct 2021 05:41:21 -0700 (PDT)
X-Received: by 2002:a05:6214:238a:: with SMTP id fw10mr11494385qvb.30.1634906481026;
Fri, 22 Oct 2021 05:41:21 -0700 (PDT)
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 05:41:20 -0700 (PDT)
In-Reply-To: <009350b5-254a-43bc-a513-5e34499da70cn@googlegroups.com>
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 12:41:21 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 101
 by: Thiago Adams - Fri, 22 Oct 2021 12:41 UTC

On Friday, October 22, 2021 at 9:19:24 AM UTC-3, Thiago Adams wrote:
> On Friday, October 22, 2021 at 9:12:54 AM UTC-3, Bart wrote:
> > On 22/10/2021 12:38, Thiago Adams wrote:
> > >
> > > What is the final type when we use typed of typedef ... ?
> > >
> > > I am trying to find out looking at samples. But what is the rule?
> > >
> > > --- GCC ---
> > >
> > > https://godbolt.org/z/fsMMzcqGz
> > >
> > > #include <stdio.h>
> > > #include <typeinfo>
> > > #include <cxxabi.h>
> > >
> > > int status;
> > > #define TYPE(EXPR) \
> > > printf("%s=", #EXPR); \
> > > printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
> > >
> > > typedef char* T1;
> > > typedef const T1 CONST_T1;
> > > typedef CONST_T1 T2[5];
> > > typedef T2 T3[2];
> > >
> > > int main()
> > > {
> > > TYPE(T1);
> > > TYPE(CONST_T1);
> > > TYPE(T2);
> > > TYPE(T3);
> > > }
> > > -----
> > > It prints:
> > >
> > > T1=char*
> > > CONST_T1=char*
> > > T2=char* [5]
> > > T3=char* [2][5]
> > >
> > > Sometimes the const disappears, like CONST_T1.
> > >
> > > changing to
> > > typedef const char* CONST_T1;
> > > then CONST_T1 prints
> > > CONST_T1=char const*
> > If I do this in my C compiler, which has the special directive $showtype:
> > typedef char* T1;
> > typedef const T1 CONST_T1;
> > typedef CONST_T1 T2[5];
> > typedef T2 T3[2];
> > $showtype T1;
> > $showtype const T1;
> > $showtype T2;
> > $showtype T3;
> >
> > then when compiling, it shows (using Algol68-style LTR type syntax):
> >
> > Type is: ref schar
> > Type is: const ref schar
> > Type is: [5]const ref schar
> > Type is: [2][5]const ref schar
> >
> > This seems to be in accordance with what gcc reports for this code:
> >
> > int main()
> > {
> > T2 a;
> > T3 b;
> >
> > a[0]=0;
> > b[0][0]=0;
> > }
> >
> > Both of those array elements are read-only.
> >
> > Perhaps your cxxabi header doesn't work properly.
> Yes it is not printing correctly.
> My question still the same but the sample can be ignored.

Looking at the samples I assumed const was disappearing but it is not.
Sorry.

So the const is always there. It just changes meaning.

typedef char* T1;
typedef const T1 T2;
//T2 is a const pointer to char*
NOT
//pointer to const char*

T2 should print
"char * const"
(it is printing char* using gcc facilities)

(
I need in my compiler to create the algorithm to convert from typedefs to
declarations (without typedefs).
I need to "move " const extract the pointers and arrays and re-arrange.
)

Re: How typedef works?

<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:a853:: with SMTP id r80mr9759917qke.275.1634906968599;
Fri, 22 Oct 2021 05:49:28 -0700 (PDT)
X-Received: by 2002:ad4:5429:: with SMTP id g9mr11042207qvt.63.1634906968411;
Fri, 22 Oct 2021 05:49:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 05:49:28 -0700 (PDT)
In-Reply-To: <87ee8d5j4x.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> <87ee8d5j4x.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 12:49:28 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 46
 by: Thiago Adams - Fri, 22 Oct 2021 12:49 UTC

On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
> Thiago Adams <thiago...@gmail.com> writes:
>
> > #include <stdio.h>
> > #include <typeinfo>
> > #include <cxxabi.h>
> >
> > int status;
> > #define TYPE(EXPR) \
> > printf("%s=", #EXPR); \
> > printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
> >
> > typedef char* T1;
> > typedef const T1 CONST_T1;
> > typedef CONST_T1 T2[5];
> > typedef T2 T3[2];
> >
> > int main()
> > {
> > TYPE(T1);
> > TYPE(CONST_T1);
> > TYPE(T2);
> > TYPE(T3);
> > }
> This is C++ behaving as specified:
>
> In all cases, top-level cv-qualifiers are ignored by typeid (that is,
> typeid(const T) == typeid(T)).
>
> https://en.cppreference.com/w/cpp/language/typeid

Interesting.

I think it is doing the same in C.

#include <stdio.h>
int main() {
const int i = 1;
printf("%s", _Generic(i,
const int : "const int",
int : "int"
));
} prints int not const int.
https://godbolt.org/z/YGsrah173

(I am implementing typeid in my compiler and I was planning to keep const.)

Re: How typedef works?

<skuc62$tce$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Oct 2021 13:52:06 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <skuc62$tce$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Oct 2021 12:52:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e030f06cd8f6adad2f34518bd1ab2da";
logging-data="30094"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XNYpxrciGIPSIz9XqKXdGFwvbImTUYXw="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:RwFr8eYPPJY4GyJPL4JzV6T+bEc=
In-Reply-To: <21aa6469-6d1e-44ec-b2ec-6594f13fea92n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211022-0, 22/10/2021), Outbound message
 by: Bart - Fri, 22 Oct 2021 12:52 UTC

On 22/10/2021 13:41, Thiago Adams wrote:
> On Friday, October 22, 2021 at 9:19:24 AM UTC-3, Thiago Adams wrote:

>>> Perhaps your cxxabi header doesn't work properly.
>> Yes it is not printing correctly.
>> My question still the same but the sample can be ignored.
>
> Looking at the samples I assumed const was disappearing but it is not.
> Sorry.
>
> So the const is always there. It just changes meaning.
>
> typedef char* T1;
> typedef const T1 T2;
> //T2 is a const pointer to char*
> NOT
> //pointer to const char*
>
> T2 should print
> "char * const"
> (it is printing char* using gcc facilities)
>
> (
> I need in my compiler to create the algorithm to convert from typedefs to
> declarations (without typedefs).
> I need to "move " const extract the pointers and arrays and re-arrange.
> )
>

If you implement typedef in a normal compiler, then the 'typedef' part
just disappears. You're left with your internal representation of the
type. Then it can be written out as you like; as C syntax if really
necessary!

But if you are doing it with just text processing, then it's going to be
challenging. Bear in mind that typedefs can be written like:

char typedef* T1;

And also:

char const const typedef *T1, T2, * const * const T3[4];

You can blame C's bizarre syntax for this. With something saner, you
just stick 'const' on the left of any type, or any part of it, that
needs to be readonly.

Re: How typedef works?

<e3c3898d-a14d-46db-94e1-61ae16959df8n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:b6c1:: with SMTP id g184mr10031496qkf.270.1634907341287;
Fri, 22 Oct 2021 05:55:41 -0700 (PDT)
X-Received: by 2002:a05:6214:1d2e:: with SMTP id f14mr7985294qvd.43.1634907341118;
Fri, 22 Oct 2021 05:55:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 05:55:40 -0700 (PDT)
In-Reply-To: <36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
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>
<87ee8d5j4x.fsf@bsb.me.uk> <36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e3c3898d-a14d-46db-94e1-61ae16959df8n@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 12:55:41 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 57
 by: Thiago Adams - Fri, 22 Oct 2021 12:55 UTC

On Friday, October 22, 2021 at 9:49:35 AM UTC-3, Thiago Adams wrote:
> On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
> > Thiago Adams <thiago...@gmail.com> writes:
> >
> > > #include <stdio.h>
> > > #include <typeinfo>
> > > #include <cxxabi.h>
> > >
> > > int status;
> > > #define TYPE(EXPR) \
> > > printf("%s=", #EXPR); \
> > > printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
> > >
> > > typedef char* T1;
> > > typedef const T1 CONST_T1;
> > > typedef CONST_T1 T2[5];
> > > typedef T2 T3[2];
> > >
> > > int main()
> > > {
> > > TYPE(T1);
> > > TYPE(CONST_T1);
> > > TYPE(T2);
> > > TYPE(T3);
> > > }
> > This is C++ behaving as specified:
> >
> > In all cases, top-level cv-qualifiers are ignored by typeid (that is,
> > typeid(const T) == typeid(T)).
> >
> > https://en.cppreference.com/w/cpp/language/typeid
> Interesting.
>
> I think it is doing the same in C.

Another sample very similar

#include <stdio.h>

int main()
{ char * const s1;
printf("%s\n", _Generic(s1,
const char* : "const char *",
char * const : "char * const",
char * : "char *"
));
//prints char *

const char * s2;
printf("%s\n", _Generic(s2,
const char* : "const char *",
char * const : "char * const",
char * : "char *"
));
//prints: const char *
}

Re: How typedef works?

<72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:6112:: with SMTP id a18mr12777188qtm.401.1634907510674;
Fri, 22 Oct 2021 05:58:30 -0700 (PDT)
X-Received: by 2002:a05:6214:118f:: with SMTP id t15mr11193736qvv.28.1634907510504;
Fri, 22 Oct 2021 05:58:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 05:58:30 -0700 (PDT)
In-Reply-To: <skuc62$tce$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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <72e142c9-c70b-4cfd-89da-6769bdf9066dn@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 12:58:30 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 40
 by: Thiago Adams - Fri, 22 Oct 2021 12:58 UTC

On Friday, October 22, 2021 at 9:52:30 AM UTC-3, Bart wrote:
> On 22/10/2021 13:41, Thiago Adams wrote:
> > On Friday, October 22, 2021 at 9:19:24 AM UTC-3, Thiago Adams wrote:
>
> >>> Perhaps your cxxabi header doesn't work properly.
> >> Yes it is not printing correctly.
> >> My question still the same but the sample can be ignored.
> >
> > Looking at the samples I assumed const was disappearing but it is not.
> > Sorry.
> >
> > So the const is always there. It just changes meaning.
> >
> > typedef char* T1;
> > typedef const T1 T2;
> > //T2 is a const pointer to char*
> > NOT
> > //pointer to const char*
> >
> > T2 should print
> > "char * const"
> > (it is printing char* using gcc facilities)
> >
> > (
> > I need in my compiler to create the algorithm to convert from typedefs to
> > declarations (without typedefs).
> > I need to "move " const extract the pointers and arrays and re-arrange.
> > )
> >
> If you implement typedef in a normal compiler, then the 'typedef' part
> just disappears. You're left with your internal representation of the
> type. Then it can be written out as you like; as C syntax if really
> necessary!

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.

Re: How typedef works?

<skucm9$5ln$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Oct 2021 14:00:45 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <skucm9$5ln$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<87ee8d5j4x.fsf@bsb.me.uk>
<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Oct 2021 13:00:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e030f06cd8f6adad2f34518bd1ab2da";
logging-data="5815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19AW2+Maqoxs5tJwiPT+Klmrrgau6lW7kw="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:f5oMZGDeAMxM72JQ5CPzDJ+TFkI=
In-Reply-To: <36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211022-0, 22/10/2021), Outbound message
 by: Bart - Fri, 22 Oct 2021 13:00 UTC

On 22/10/2021 13:49, Thiago Adams wrote:
> On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
>> Thiago Adams <thiago...@gmail.com> writes:
>>
>>> #include <stdio.h>
>>> #include <typeinfo>
>>> #include <cxxabi.h>
>>>
>>> int status;
>>> #define TYPE(EXPR) \
>>> printf("%s=", #EXPR); \
>>> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
>>>
>>> typedef char* T1;
>>> typedef const T1 CONST_T1;
>>> typedef CONST_T1 T2[5];
>>> typedef T2 T3[2];
>>>
>>> int main()
>>> {
>>> TYPE(T1);
>>> TYPE(CONST_T1);
>>> TYPE(T2);
>>> TYPE(T3);
>>> }
>> This is C++ behaving as specified:
>>
>> In all cases, top-level cv-qualifiers are ignored by typeid (that is,
>> typeid(const T) == typeid(T)).
>>
>> https://en.cppreference.com/w/cpp/language/typeid
>
> Interesting.
>
> I think it is doing the same in C.
>
> #include <stdio.h>
> int main() {
> const int i = 1;
> printf("%s", _Generic(i,
> const int : "const int",
> int : "int"
> ));
> }
> prints int not const int.
> https://godbolt.org/z/YGsrah173

My 'bcc' compiler shows 'const int'.

I don't why gcc shows only 'int' (as do clang and tcc, but there I know
why: they are just copying gcc).

All compilers have trouble using Generic for array types, probably to do
with the decaying of array expressions to pointers.

On mine, I also have typeof(), and $showmode which works on expressions
not types. Then this:

const int i = 1;
$showtype typeof(i);
$showmode i;

shows both as 'const int'.

Re: How typedef works?

<skus8j$7u4$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!DlgLRg+VHgX+keYJDqJrig.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: Fri, 22 Oct 2021 19:26:27 +0200
Organization: Aioe.org NNTP Server
Message-ID: <skus8j$7u4$1@gioia.aioe.org>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="8132"; posting-host="DlgLRg+VHgX+keYJDqJrig.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: fr
 by: Guillaume - Fri, 22 Oct 2021 17:26 UTC

Le 22/10/2021 à 13:38, Thiago Adams a écrit :
>
> What is the final type when we use typed of typedef ... ?
>
> I am trying to find out looking at samples. But what is the rule?
>
> --- GCC ---
>
> https://godbolt.org/z/fsMMzcqGz
>
> #include <stdio.h>
> #include <typeinfo>
> #include <cxxabi.h>

'typeinfo' and 'cxxabi.h' are not standard C headers. Your TYPE() macro
is C++. Why post in comp.lang.c?

Re: How typedef works?

<20211022103054.185@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: Fri, 22 Oct 2021 17:31:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20211022103054.185@kylheku.com>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<skus8j$7u4$1@gioia.aioe.org>
Injection-Date: Fri, 22 Oct 2021 17:31:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="86d7c6a7358371e694f35e48c8bf10c6";
logging-data="17607"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7Oj7Ad91gq+rn1kNGVIvnekAHQo5OcO0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:6kf5RU4yeXhysimbeHLRCLwFSfU=
 by: Kaz Kylheku - Fri, 22 Oct 2021 17:31 UTC

On 2021-10-22, Guillaume <message@bottle.org> wrote:
> Le 22/10/2021 ?? 13:38, Thiago Adams a ??crit??:
>>
>> What is the final type when we use typed of typedef ... ?
>>
>> I am trying to find out looking at samples. But what is the rule?
>>
>> --- GCC ---
>>
>> https://godbolt.org/z/fsMMzcqGz
>>
>> #include <stdio.h>
>> #include <typeinfo>
>> #include <cxxabi.h>
>
>
> 'typeinfo' and 'cxxabi.h' are not standard C headers. Your TYPE() macro
> is C++. Why post in comp.lang.c?

Because Google Groups?

Re: How typedef works?

<skuu76$qeq$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: How typedef works?
Date: Fri, 22 Oct 2021 20:00:06 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <skuu76$qeq$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<skus8j$7u4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Oct 2021 18:00:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="84e67164a95738d13f15bef329859b12";
logging-data="27098"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z3VqLTVgNONitNalEaDRUsfs9Zj/osq0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.2.0
Cancel-Lock: sha1:roUSwAbH4AqGtbzWWwVh6LDWNHU=
In-Reply-To: <skus8j$7u4$1@gioia.aioe.org>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Oct 2021 18:00 UTC

Am 22.10.2021 um 19:26 schrieb Guillaume:
> Le 22/10/2021 à 13:38, Thiago Adams a écrit :
>>
>> What is the final type when we use typed of typedef ... ?
>>
>> I am trying to find out looking at samples. But what is the rule?
>>
>> --- GCC ---
>>
>> https://godbolt.org/z/fsMMzcqGz
>>
>> #include <stdio.h>
>> #include <typeinfo>
>> #include <cxxabi.h>
>
>
> 'typeinfo' and 'cxxabi.h' are not standard C headers. Your TYPE() macro
> is C++. Why post in comp.lang.c?

Because you could mostly use a C++-compiler like it would be
a C-compiler and use some features for debugging. There some
tiny differences that would make a .cpp-program not compilable
in C-mode later, but that's easy to circuvent.

Re: How typedef works?

<bdac4989-42ef-47a8-808d-aa9024e0a63dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:584d:: with SMTP id h13mr1546320qth.267.1634925860934;
Fri, 22 Oct 2021 11:04:20 -0700 (PDT)
X-Received: by 2002:a05:622a:1754:: with SMTP id l20mr1539213qtk.309.1634925860697;
Fri, 22 Oct 2021 11:04:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 11:04:20 -0700 (PDT)
In-Reply-To: <20211022103054.185@kylheku.com>
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>
<skus8j$7u4$1@gioia.aioe.org> <20211022103054.185@kylheku.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bdac4989-42ef-47a8-808d-aa9024e0a63dn@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 18:04:20 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 24
 by: Thiago Adams - Fri, 22 Oct 2021 18:04 UTC

On Friday, October 22, 2021 at 2:31:18 PM UTC-3, Kaz Kylheku wrote:
> On 2021-10-22, Guillaume <mes...@bottle.org> wrote:
> > Le 22/10/2021 ?? 13:38, Thiago Adams a ??crit??:
> >>
> >> What is the final type when we use typed of typedef ... ?
> >>
> >> I am trying to find out looking at samples. But what is the rule?
> >>
> >> --- GCC ---
> >>
> >> https://godbolt.org/z/fsMMzcqGz
> >>
> >> #include <stdio.h>
> >> #include <typeinfo>
> >> #include <cxxabi.h>
> >
> >
> > 'typeinfo' and 'cxxabi.h' are not standard C headers. Your TYPE() macro
> > is C++. Why post in comp.lang.c?
> Because Google Groups?

The C++ part was not important to the question.
I was used to print the name of the type only.

Re: How typedef works?

<bf100415-2ebd-4628-89ef-725734e281e0n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:29c9:: with SMTP id gh9mr1545610qvb.50.1634927386428;
Fri, 22 Oct 2021 11:29:46 -0700 (PDT)
X-Received: by 2002:ac8:4159:: with SMTP id e25mr1682276qtm.69.1634927386203;
Fri, 22 Oct 2021 11:29:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Oct 2021 11:29:46 -0700 (PDT)
In-Reply-To: <skucm9$5ln$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>
<87ee8d5j4x.fsf@bsb.me.uk> <36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
<skucm9$5ln$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bf100415-2ebd-4628-89ef-725734e281e0n@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 18:29:46 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 71
 by: Thiago Adams - Fri, 22 Oct 2021 18:29 UTC

On Friday, October 22, 2021 at 10:01:10 AM UTC-3, Bart wrote:
> On 22/10/2021 13:49, Thiago Adams wrote:
> > On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
> >> Thiago Adams <thiago...@gmail.com> writes:
> >>
> >>> #include <stdio.h>
> >>> #include <typeinfo>
> >>> #include <cxxabi.h>
> >>>
> >>> int status;
> >>> #define TYPE(EXPR) \
> >>> printf("%s=", #EXPR); \
> >>> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
> >>>
> >>> typedef char* T1;
> >>> typedef const T1 CONST_T1;
> >>> typedef CONST_T1 T2[5];
> >>> typedef T2 T3[2];
> >>>
> >>> int main()
> >>> {
> >>> TYPE(T1);
> >>> TYPE(CONST_T1);
> >>> TYPE(T2);
> >>> TYPE(T3);
> >>> }
> >> This is C++ behaving as specified:
> >>
> >> In all cases, top-level cv-qualifiers are ignored by typeid (that is,
> >> typeid(const T) == typeid(T)).
> >>
> >> https://en.cppreference.com/w/cpp/language/typeid
> >
> > Interesting.
> >
> > I think it is doing the same in C.
> >
> > #include <stdio.h>
> > int main() {
> > const int i = 1;
> > printf("%s", _Generic(i,
> > const int : "const int",
> > int : "int"
> > ));
> > }
> > prints int not const int.
> > https://godbolt.org/z/YGsrah173
> My 'bcc' compiler shows 'const int'.
>
> I don't why gcc shows only 'int' (as do clang and tcc, but there I know
> why: they are just copying gcc).
>
> All compilers have trouble using Generic for array types, probably to do
> with the decaying of array expressions to pointers.
>
> On mine, I also have typeof(), and $showmode which works on expressions
> not types. Then this:
> const int i = 1;
> $showtype typeof(i);
> $showmode i;
>
> shows both as 'const int'.

typedef void* (*T1)(char, char);
typedef const T1 (*T2)(double);
typedef volatile T2 (*T3)[3];

what does your compiler prints for:

$showtype typeof(T3);

I want to figure out how to merge these typedefs.

Re: How typedef works?

<typedef-const-20211022195745@ram.dialup.fu-berlin.de>

  copy mid

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

  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 18:58:34 GMT
Organization: Stefan Ram
Lines: 14
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <typedef-const-20211022195745@ram.dialup.fu-berlin.de>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de BdF5LCUknjvxSuxehVy+IQZGwYEeTtEe3fBEnreK0MdMdv
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 18:58 UTC

Thiago Adams <thiago.adams@gmail.com> writes:
> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))

With "::", it can't be C.

The error message for the following program shows
that "const" has become part of "ic":

int main( void )
{ typedef int const ic;
ic i = 0;
int * p = &i; }

Re: How typedef works?

<skv1ov$ob6$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Oct 2021 20:00:33 +0100
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <skv1ov$ob6$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<87ee8d5j4x.fsf@bsb.me.uk>
<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
<skucm9$5ln$1@dont-email.me>
<bf100415-2ebd-4628-89ef-725734e281e0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Oct 2021 19:00:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e030f06cd8f6adad2f34518bd1ab2da";
logging-data="24934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19m5v5oezROczWpC337JrLzvinM92Fw8yo="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:rZnmQu5AoZsddEAVcHo3YZtwZ7M=
In-Reply-To: <bf100415-2ebd-4628-89ef-725734e281e0n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211022-6, 22/10/2021), Outbound message
 by: Bart - Fri, 22 Oct 2021 19:00 UTC

On 22/10/2021 19:29, Thiago Adams wrote:
> On Friday, October 22, 2021 at 10:01:10 AM UTC-3, Bart wrote:
>> On 22/10/2021 13:49, Thiago Adams wrote:
>>> On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
>>>> Thiago Adams <thiago...@gmail.com> writes:
>>>>
>>>>> #include <stdio.h>
>>>>> #include <typeinfo>
>>>>> #include <cxxabi.h>
>>>>>
>>>>> int status;
>>>>> #define TYPE(EXPR) \
>>>>> printf("%s=", #EXPR); \
>>>>> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
>>>>>
>>>>> typedef char* T1;
>>>>> typedef const T1 CONST_T1;
>>>>> typedef CONST_T1 T2[5];
>>>>> typedef T2 T3[2];
>>>>>
>>>>> int main()
>>>>> {
>>>>> TYPE(T1);
>>>>> TYPE(CONST_T1);
>>>>> TYPE(T2);
>>>>> TYPE(T3);
>>>>> }
>>>> This is C++ behaving as specified:
>>>>
>>>> In all cases, top-level cv-qualifiers are ignored by typeid (that is,
>>>> typeid(const T) == typeid(T)).
>>>>
>>>> https://en.cppreference.com/w/cpp/language/typeid
>>>
>>> Interesting.
>>>
>>> I think it is doing the same in C.
>>>
>>> #include <stdio.h>
>>> int main() {
>>> const int i = 1;
>>> printf("%s", _Generic(i,
>>> const int : "const int",
>>> int : "int"
>>> ));
>>> }
>>> prints int not const int.
>>> https://godbolt.org/z/YGsrah173
>> My 'bcc' compiler shows 'const int'.
>>
>> I don't why gcc shows only 'int' (as do clang and tcc, but there I know
>> why: they are just copying gcc).
>>
>> All compilers have trouble using Generic for array types, probably to do
>> with the decaying of array expressions to pointers.
>>
>> On mine, I also have typeof(), and $showmode which works on expressions
>> not types. Then this:
>> const int i = 1;
>> $showtype typeof(i);
>> $showmode i;
>>
>> shows both as 'const int'.
>
> typedef void* (*T1)(char, char);
> typedef const T1 (*T2)(double);
> typedef volatile T2 (*T3)[3];
>
> what does your compiler prints for:
>
> $showtype typeof(T3);
>
> I want to figure out how to merge these typedefs.
>

It shows:

Type is: ref [3]ref proc(double)const ref proc(schar,schar)ref void

Read left-to-right:

'ref' means 'pointer to'
'[n]' means 'array n of'
'proc' means 'function'
'schar' means 'signed char'
'(...)' encloses a parameter list, followed by the return type

'volatile' is ignored; just assume to works like const.

(If you're on Windows (or maybe running Wine), you can try it yourself:

https://github.com/sal55/langs/blob/master/bcc.exe

(This is a UPX-compressed version; just run it as normal.)

Use -c when compiling if there is no 'main': bcc -c prog.c

Use $showtype T; outside of a function only. ($showmode X; goes inside a
function; can't remember why...)

You need to use either main(void), or -old option to allow main().)

Re: How typedef works?

<skv2aa$scl$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Oct 2021 20:09:49 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <skv2aa$scl$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<87ee8d5j4x.fsf@bsb.me.uk>
<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
<skucm9$5ln$1@dont-email.me>
<bf100415-2ebd-4628-89ef-725734e281e0n@googlegroups.com>
<skv1ov$ob6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Oct 2021 19:10:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e030f06cd8f6adad2f34518bd1ab2da";
logging-data="29077"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lmn+NvEW5xHTdMJ2gSGEdqTK+r3AvgaY="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:NHJy/DIAOkp08HaBSfv5Vpoozpo=
In-Reply-To: <skv1ov$ob6$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211022-6, 22/10/2021), Outbound message
 by: Bart - Fri, 22 Oct 2021 19:09 UTC

On 22/10/2021 20:00, Bart wrote:
> On 22/10/2021 19:29, Thiago Adams wrote:

>> I want to figure out how to merge these typedefs.
>>
>

> (If you're on Windows (or maybe running Wine), you can try it yourself:
>
>   https://github.com/sal55/langs/blob/master/bcc.exe
>
> (This is a UPX-compressed version; just run it as normal.)
>
> Use -c when compiling if there is no 'main': bcc -c prog.c
>
> Use $showtype T; outside of a function only. ($showmode X; goes inside a
> function; can't remember why...)
>
> You need to use either main(void), or -old option to allow main().)

Perhaps simpler, use:

bcc -debug prog.c

This writes some debug info to bcc.log, including a symbol table
listing. That will show the typedefs (T1, T2, T3 for your example) and
their types.

Re: How typedef works?

<878ryk69xl.fsf@bsb.me.uk>

  copy mid

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

  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: Fri, 22 Oct 2021 22:12:22 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <878ryk69xl.fsf@bsb.me.uk>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<87ee8d5j4x.fsf@bsb.me.uk>
<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a3bb1bc3dae98cca541349f73000b53d";
logging-data="6777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18K3ovzVBvx0NInfF4wAnMs1l4HZYxdRnA="
Cancel-Lock: sha1:UF8W8G2J/oUUJe1Sp4a41hOv/Qo=
sha1:C/+/wK6+yZUy1y8seQyFEoWvuVg=
X-BSB-Auth: 1.b9fb2b69135c0f5331b3.20211022221222BST.878ryk69xl.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 22 Oct 2021 21:12 UTC

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

> On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
>> Thiago Adams <thiago...@gmail.com> writes:
>>
>> > #include <stdio.h>
>> > #include <typeinfo>
>> > #include <cxxabi.h>
>> >
>> > int status;
>> > #define TYPE(EXPR) \
>> > printf("%s=", #EXPR); \
>> > printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
>> >
>> > typedef char* T1;
>> > typedef const T1 CONST_T1;
>> > typedef CONST_T1 T2[5];
>> > typedef T2 T3[2];
>> >
>> > int main()
>> > {
>> > TYPE(T1);
>> > TYPE(CONST_T1);
>> > TYPE(T2);
>> > TYPE(T3);
>> > }
>> This is C++ behaving as specified:
>>
>> In all cases, top-level cv-qualifiers are ignored by typeid (that is,
>> typeid(const T) == typeid(T)).
>>
>> https://en.cppreference.com/w/cpp/language/typeid
>
> Interesting.
>
> I think it is doing the same in C.
>
> #include <stdio.h>
> int main() {
> const int i = 1;
> printf("%s", _Generic(i,
> const int : "const int",
> int : "int"
> ));
> }
> prints int not const int.

Yes, but for a different reason:

6.3.2.1

2 Except when it is the operand of the sizeof operator, the _Alignof
operator, the unary & operator, the ++ operator, the -- operator, or
the left operand of the . operator or an assignment operator, an
lvalue that does not have array type is converted to the value
stored in the designated object (and is no longer an lvalue); this
is called lvalue conversion. If the lvalue has qualified type, the
value has the unqualified version of the type of the lvalue;
additionally ...

--
Ben.

Re: How typedef works?

<8735os69l6.fsf@bsb.me.uk>

  copy mid

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

  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: Fri, 22 Oct 2021 22:19:49 +0100
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <8735os69l6.fsf@bsb.me.uk>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<87ee8d5j4x.fsf@bsb.me.uk>
<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
<skucm9$5ln$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a3bb1bc3dae98cca541349f73000b53d";
logging-data="6777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19miwjfLY5sUUwcpj6R6uCUdOCuw++gqrw="
Cancel-Lock: sha1:B+YduOXb/ppb48c5E3UU+HpFTng=
sha1:PMaX9UBRAKnREr/386a+EQ0i2ts=
X-BSB-Auth: 1.cde1520f8a4109876d00.20211022221949BST.8735os69l6.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 22 Oct 2021 21:19 UTC

Bart <bc@freeuk.com> writes:

> On 22/10/2021 13:49, Thiago Adams wrote:
>> On Friday, October 22, 2021 at 9:39:05 AM UTC-3, Ben Bacarisse wrote:
>>> Thiago Adams <thiago...@gmail.com> writes:
>>>
>>>> #include <stdio.h>
>>>> #include <typeinfo>
>>>> #include <cxxabi.h>
>>>>
>>>> int status;
>>>> #define TYPE(EXPR) \
>>>> printf("%s=", #EXPR); \
>>>> printf("%s\n", abi::__cxa_demangle(typeid(typeof(EXPR)).name(),0,0,&status))
>>>>
>>>> typedef char* T1;
>>>> typedef const T1 CONST_T1;
>>>> typedef CONST_T1 T2[5];
>>>> typedef T2 T3[2];
>>>>
>>>> int main()
>>>> {
>>>> TYPE(T1);
>>>> TYPE(CONST_T1);
>>>> TYPE(T2);
>>>> TYPE(T3);
>>>> }
>>> This is C++ behaving as specified:
>>>
>>> In all cases, top-level cv-qualifiers are ignored by typeid (that is,
>>> typeid(const T) == typeid(T)).
>>>
>>> https://en.cppreference.com/w/cpp/language/typeid
>> Interesting.
>> I think it is doing the same in C.
>> #include <stdio.h>
>> int main() {
>> const int i = 1;
>> printf("%s", _Generic(i,
>> const int : "const int",
>> int : "int"
>> ));
>> }
>> prints int not const int.
>> https://godbolt.org/z/YGsrah173
>
> My 'bcc' compiler shows 'const int'.

A conforming implementation should display int.

> I don't why gcc shows only 'int' (as do clang and tcc, but there I
> know why: they are just copying gcc).

They may be copying gcc, but then gcc is often a good implementation to
copy. Anyway, they are all correct to give the result they do. See my
other reply for why.

> All compilers have trouble using Generic for array types, probably to
> do with the decaying of array expressions to pointers.

It's more likely that they all implement C as specified. Some may not,
in all cases, but apart from the issue with yours that you pointed out I
don't know of any.

> On mine, I also have typeof(), and $showmode which works on
> expressions not types. Then this:
>
> const int i = 1;
> $showtype typeof(i);
> $showmode i;
>
> shows both as 'const int'.

Do you really mean it outputs a string? I'd have provided an operator
that returns a string.

--
Ben.

Re: How typedef works?

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

  copy mid

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

  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: Fri, 22 Oct 2021 22:25:52 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <87wnm44uqn.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>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a3bb1bc3dae98cca541349f73000b53d";
logging-data="6777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cn0Enp/zsMRxkm2NTLDjbdf022J9j1ig="
Cancel-Lock: sha1:zJwvn9jl7Yl5QMROao+FixPBFh0=
sha1:EhdNGCSDxt9L3XCJexStFJcYDL4=
X-BSB-Auth: 1.06b9b2dfe07b7fe88939.20211022222552BST.87wnm44uqn.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 22 Oct 2021 21:25 UTC

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

> Looking at the samples I assumed const was disappearing but it is not.
> Sorry.
>
> So the const is always there. It just changes meaning.

Eh?

> typedef char* T1;
> typedef const T1 T2;
> //T2 is a const pointer to char*

No. You can't have thought it meant that. Did you mean to write "T2 is
const pointer to char"?

> NOT
> //pointer to const char*

As above. Did you mean to write "pointer to const char"?

> T2 should print
> "char * const"

What do you mean by "should"? See the quotes I gave about C++'s
type_info class and C's _Generic.

--
Ben.

Re: How typedef works?

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

  copy mid

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

  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: Fri, 22 Oct 2021 22:35:47 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <87o87g4ua4.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>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a3bb1bc3dae98cca541349f73000b53d";
logging-data="6777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4TjlcHo53qGbGZsokqveEaIrcremPBbU="
Cancel-Lock: sha1:9ITmv9rPmKb7DTEQDZL69msqF7o=
sha1:IXB8lW8BqiuZOnimmKy/z2Lh+3Q=
X-BSB-Auth: 1.09b5ace0dd5d03b34a5c.20211022223547BST.87o87g4ua4.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 22 Oct 2021 21:35 UTC

Thiago Adams <thiago.adams@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.

--
Ben.

Re: How typedef works?

<27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a0c:eec7:: with SMTP id h7mr736776qvs.25.1634943257619;
Fri, 22 Oct 2021 15:54:17 -0700 (PDT)
X-Received: by 2002:a37:9e57:: with SMTP id h84mr2395341qke.480.1634943257422;
Fri, 22 Oct 2021 15:54:17 -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: Fri, 22 Oct 2021 15:54:17 -0700 (PDT)
In-Reply-To: <87o87g4ua4.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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <27a252d6-1fb4-460f-ae07-043603ea2271n@googlegroups.com>
Subject: Re: How typedef works?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Fri, 22 Oct 2021 22:54:17 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Thiago Adams - Fri, 22 Oct 2021 22:54 UTC

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 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.

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.

Re: How typedef works?

<type-20211023000414@ram.dialup.fu-berlin.de>

  copy mid

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

  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:05:26 GMT
Organization: Stefan Ram
Lines: 7
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <type-20211023000414@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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de vevqSXNhcohrIkuiUkoMigd9Mx78rExO8RYLb3mxYGrfj5
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:05 UTC

Thiago Adams <thiago.adams@gmail.com> 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).

Re: How typedef works?

<skvga0$r2h$1@dont-email.me>

  copy mid

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

  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 00:08:35 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <skvga0$r2h$1@dont-email.me>
References: <b66f6eef-ab4a-4331-bb41-7789c9a938f3n@googlegroups.com>
<87ee8d5j4x.fsf@bsb.me.uk>
<36b9275a-e62b-4cc8-952a-ef9da5ead2c7n@googlegroups.com>
<skucm9$5ln$1@dont-email.me> <8735os69l6.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Oct 2021 23:08:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1e86dde5be44ad674ae104cbdba1e811";
logging-data="27729"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FJ4ieqGGqztd/6So4hrhCQ/dk0JSHbW8="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:2ZzPTpoTAcv6tNvDZElakRnpQSA=
In-Reply-To: <8735os69l6.fsf@bsb.me.uk>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211022-6, 22/10/2021), Outbound message
 by: Bart - Fri, 22 Oct 2021 23:08 UTC

On 22/10/2021 22:19, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:

>> My 'bcc' compiler shows 'const int'.
>
> A conforming implementation should display int.

I understand now that for such expressions, the leftmost 'const' (if it
were to be expressed left to right) of the type of an expression is removed.

>> On mine, I also have typeof(), and $showmode which works on
>> expressions not types. Then this:
>>
>> const int i = 1;
>> $showtype typeof(i);
>> $showmode i;
>>
>> shows both as 'const int'.
>
> Do you really mean it outputs a string? I'd have provided an operator
> that returns a string.

The compiler displays a message, for debugging purposes; there is no
runtime code generated.

However, delving into my source code, I see that there is a version of
$showtype that can be used like this:

puts(strtype(typeof(i)));

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor