Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Doubt is not a pleasant condition, but certainty is absurd. -- Voltaire


devel / comp.lang.c / on the order of the const-keyword

SubjectAuthor
* on the order of the const-keywordMeredith Montgomery
+- Re: on the order of the const-keywordStefan Ram
+- Re: on the order of the const-keywordStefan Ram
+* Re: on the order of the const-keywordBart
|+* Re: on the order of the const-keywordjames...@alumni.caltech.edu
||+- Re: on the order of the const-keywordGuillaume
||`* Re: on the order of the const-keywordMeredith Montgomery
|| `- Re: on the order of the const-keywordJames Kuyper
|+* Re: on the order of the const-keywordThiago Adams
||`* Re: on the order of the const-keywordThiago Adams
|| +* Re: on the order of the const-keywordBart
|| |`* Re: on the order of the const-keywordThiago Adams
|| | `* Re: on the order of the const-keywordThiago Adams
|| |  +- Re: on the order of the const-keywordBart
|| |  `* Re: on the order of the const-keywordKeith Thompson
|| |   `- Re: on the order of the const-keywordBen Bacarisse
|| +- Re: on the order of the const-keywordBen Bacarisse
|| +- Re: on the order of the const-keywordKeith Thompson
|| `- Re: on the order of the const-keywordMeredith Montgomery
|`- Re: on the order of the const-keywordMeredith Montgomery
+* Re: on the order of the const-keywordJames Kuyper
|`- Re: on the order of the const-keywordMeredith Montgomery
`* Re: on the order of the const-keywordDavid Brown
 +* Re: on the order of the const-keywordBart
 |`* Re: on the order of the const-keywordDavid Brown
 | `* Re: on the order of the const-keywordBart
 |  `* Re: on the order of the const-keywordDavid Brown
 |   +* Re: on the order of the const-keywordManfred
 |   |+- Re: on the order of the const-keywordMeredith Montgomery
 |   |`- Re: on the order of the const-keywordBen Bacarisse
 |   `- Re: on the order of the const-keywordBart
 `* Re: on the order of the const-keywordMeredith Montgomery
  `* Re: on the order of the const-keywordDavid Brown
   `- Re: on the order of the const-keywordMeredith Montgomery

Pages:12
on the order of the const-keyword

<86mtmtm9m1.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!EKCVjuy47ovTI5d14PUybA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: on the order of the const-keyword
Date: Thu, 28 Oct 2021 12:50:46 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86mtmtm9m1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="61082"; posting-host="EKCVjuy47ovTI5d14PUybA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:e+LKAjpH4y7O2ArMWTKAEZ44t6Y=
 by: Meredith Montgomery - Thu, 28 Oct 2021 15:50 UTC

These seem legal declarations in C:

const char msg[9] = "warming:";
char const msg[9] = "warming:";

What's the difference between them?

(*) Note to self

When I tried changing that array, the compiler did not let me to ---
with either declaration. (So it appears there is no *effective*
difference.)

%cat msg.c
#include <stdio.h>

int main(void) {

char const msg[9] = "warming:";
msg[0]= 'f';
printf("%s\n", msg);

} %make msg
gcc msg.c -o msg
msg.c: In function 'main':
msg.c:6:9: error: assignment of read-only location 'msg[0]'
6 | msg[0]= 'f';
| ^
make: *** [<builtin>: msg] Error 1
%

Re: on the order of the const-keyword

<const-20211028171419@ram.dialup.fu-berlin.de>

  copy mid

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

  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: on the order of the const-keyword
Date: 28 Oct 2021 16:20:26 GMT
Organization: Stefan Ram
Lines: 56
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <const-20211028171419@ram.dialup.fu-berlin.de>
References: <86mtmtm9m1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 0IlzG4dHV9JRmYrGngrmGAtkW847BwtaY1Y2KTJht4GWDw
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 - Thu, 28 Oct 2021 16:20 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:
>const char msg[9] = "warming:";
>char const msg[9] = "warming:";
>What's the difference between them?

After,

typedef void * pointer;
const pointer p;

. "p" is a /const/ pointer, /not/ a pointer to const!
One cannot simple "insert the typedef", which would yield:

const pointer p; -->
const void * p;

, "const void * p;" would means that "p" is a "pointer to
const", but "const pointer p;" really means that p is a
"const pointer to mutable".

. This is made more clear for humans when written as

pointer const p;

, although in C "const pointer p;" and "pointer const p;"
are equivalent.

~

When one uses a "read-from-right-to -eft rule",

char const * const p;

is more natural, because, when we reverse the text
word-by-word, we get

; p const * const char

, pronounce:

; p const * const char
er, p is a const pointer to a const char object

~

The C grammar:

<declaration>::=<declaration-specifiers>[<init-declarator-list>]";".
<declaration-specifiers>::=<type-qualifier>[<declaration-specifiers>].
<type-qualifier>::="const"|"restrict"|"volatile".

~

Thanks go to Dan Sacks for ideas used in this post.

Re: on the order of the const-keyword

<const-20211028172138@ram.dialup.fu-berlin.de>

  copy mid

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

  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: on the order of the const-keyword
Supersedes: <const-20211028171419@ram.dialup.fu-berlin.de>
Date: 28 Oct 2021 16:22:14 GMT
Organization: Stefan Ram
Lines: 61
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <const-20211028172138@ram.dialup.fu-berlin.de>
References: <86mtmtm9m1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de VwoLubEZfxMFT8pcBoYUmg1hk11HIsWg8uCuUjpRlGRFxa
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 - Thu, 28 Oct 2021 16:22 UTC

Supersedes: <const-20211028171419@ram.dialup.fu-berlin.de>
[corrected typos]

Meredith Montgomery <mmontgomery@levado.to> writes:
>const char msg[9] = "warming:";
>char const msg[9] = "warming:";
>What's the difference between them?

After,

typedef void * pointer;
const pointer p;

. "p" is a /const/ pointer, /not/ a pointer to const!
One cannot simple "insert the typedef", which would yield:

const pointer p; -->
const void * p;

, "const void * p;" would mean that "p" is a "pointer to
const", but "const pointer p;" really means that p is a
"const pointer to mutable".

. This is made more clear for humans when written as

pointer const p;

, although in C "const pointer p;" and "pointer const p;"
are equivalent.

~

When one uses a "read-from-right-to-left rule",

char const * const p;

is more natural, because, when we reverse the text
word-by-word, we get

; p const * const char

, pronounce:

; p const * const char
er, p is a const pointer to a const char object

~

The C grammar:

<declaration>::=<declaration-specifiers>[<init-declarator-list>]";".
<declaration-specifiers>::=<type-qualifier>[<declaration-specifiers>].
<type-qualifier>::="const"|"restrict"|"volatile".

.

~

Thanks go to Dan Sacks for ideas used in this post.

Re: on the order of the const-keyword

<sleiul$8m0$1@dont-email.me>

  copy mid

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

  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: on the order of the const-keyword
Date: Thu, 28 Oct 2021 17:25:48 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <sleiul$8m0$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Oct 2021 16:25:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d6027a00a062ce1d57bc54c3c817b675";
logging-data="8896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wk8FTF8cYF3K7FldIVVnTYwCYLJrUVyI="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:v5ImvfU8SZjaBKGEULvik+utU54=
In-Reply-To: <86mtmtm9m1.fsf@levado.to>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211028-2, 28/10/2021), Outbound message
 by: Bart - Thu, 28 Oct 2021 16:25 UTC

On 28/10/2021 16:50, Meredith Montgomery wrote:
> These seem legal declarations in C:
>
> const char msg[9] = "warming:";
> char const msg[9] = "warming:";
>
> What's the difference between them?

There is no difference. You can even write:

const char const msg[9];

'const' (as well as short, int, long, float, double, even static and
typedef) can occur anywhere, in any combination, in the declaration of a
base type (what goes on the left before the first variable).

'const' can also be repeated any number of times:

char const const const const const const msg[9]

if you want to be certain that msg is constant!

However when applied to a pointer, then it must go after *.

Re: on the order of the const-keyword

<slel67$ppc$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Thu, 28 Oct 2021 13:04:07 -0400
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <slel67$ppc$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Oct 2021 17:04:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="350375f7f0236cda0144d652d5c73df3";
logging-data="26412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187u/eYRk1313ANmFLcCl0htjW5bGJ1rvI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:XhWL+xnEhx5CdxLYzpIwLJiNaes=
In-Reply-To: <86mtmtm9m1.fsf@levado.to>
Content-Language: en-US
 by: James Kuyper - Thu, 28 Oct 2021 17:04 UTC

On 10/28/21 11:50 AM, Meredith Montgomery wrote:
> These seem legal declarations in C:
>
> const char msg[9] = "warming:";
> char const msg[9] = "warming:";
>
> What's the difference between them?
>
> (*) Note to self
>
> When I tried changing that array, the compiler did not let me to ---
> with either declaration. (So it appears there is no *effective*
> difference.)
>
> %cat msg.c
> #include <stdio.h>
>
> int main(void) {
>
> char const msg[9] = "warming:";
> msg[0]= 'f';
> printf("%s\n", msg);
>
> }
> %make msg
> gcc msg.c -o msg
> msg.c: In function 'main':
> msg.c:6:9: error: assignment of read-only location 'msg[0]'
> 6 | msg[0]= 'f';
> | ^
> make: *** [<builtin>: msg] Error 1
> %
>

"const" is a type qualifier. "char" is a type specifier. Both are
members of the larger category called "declaration specifiers". If you
have a string of declaration specifiers, they can occur in any order you
like, without any change of meaning.

Re: on the order of the const-keyword

<2a5589c2-89ac-4d77-a91d-508c00f75e43n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:4003:: with SMTP id h3mr4662867qko.277.1635441051041;
Thu, 28 Oct 2021 10:10:51 -0700 (PDT)
X-Received: by 2002:a05:620a:2994:: with SMTP id r20mr4617669qkp.213.1635441050848;
Thu, 28 Oct 2021 10:10:50 -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: Thu, 28 Oct 2021 10:10:50 -0700 (PDT)
In-Reply-To: <sleiul$8m0$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=108.48.119.9; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.48.119.9
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a5589c2-89ac-4d77-a91d-508c00f75e43n@googlegroups.com>
Subject: Re: on the order of the const-keyword
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Thu, 28 Oct 2021 17:10:51 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 12
 by: james...@alumni.calt - Thu, 28 Oct 2021 17:10 UTC

On Thursday, October 28, 2021 at 12:26:09 PM UTC-4, Bart wrote:
....
> 'const' (as well as short, int, long, float, double, even static and
> typedef) can occur anywhere, in any combination, in the declaration of a
> base type (what goes on the left before the first variable).
....
> However when applied to a pointer, then it must go after *.

const char * p
char * const q;
char const * const r;

are all permitted. p is a pointer to const char. q is a const pointer to char. r is a const pointer to const char.

Re: on the order of the const-keyword

<sleqrn$d2j$1@gioia.aioe.org>

  copy mid

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

  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: on the order of the const-keyword
Date: Thu, 28 Oct 2021 20:40:53 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sleqrn$d2j$1@gioia.aioe.org>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<2a5589c2-89ac-4d77-a91d-508c00f75e43n@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="13395"; 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:91.0) Gecko/20100101
Thunderbird/91.2.1
Content-Language: fr
X-Notice: Filtered by postfilter v. 0.9.2
 by: Guillaume - Thu, 28 Oct 2021 18:40 UTC

Le 28/10/2021 à 19:10, james...@alumni.caltech.edu a écrit :
> On Thursday, October 28, 2021 at 12:26:09 PM UTC-4, Bart wrote:
> ...
>> 'const' (as well as short, int, long, float, double, even static and
>> typedef) can occur anywhere, in any combination, in the declaration of a
>> base type (what goes on the left before the first variable).
> ...
>> However when applied to a pointer, then it must go after *.
>
> const char * p
> char * const q;
> char const * const r;
>
> are all permitted. p is a pointer to const char. q is a const pointer to char. r is a const pointer to const char.

Yes indeed!
With pointer declarations, 'const' has a different meaning depending on
where it is located relative to '*', as you showed.

Re: on the order of the const-keyword

<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:ae83:: with SMTP id x125mr5457580qke.37.1635450971105;
Thu, 28 Oct 2021 12:56:11 -0700 (PDT)
X-Received: by 2002:a05:620a:902:: with SMTP id v2mr5495254qkv.480.1635450970866;
Thu, 28 Oct 2021 12:56:10 -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: Thu, 28 Oct 2021 12:56:10 -0700 (PDT)
In-Reply-To: <sleiul$8m0$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: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
Subject: Re: on the order of the const-keyword
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Thu, 28 Oct 2021 19:56:11 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: Thiago Adams - Thu, 28 Oct 2021 19:56 UTC

On Thursday, October 28, 2021 at 1:26:09 PM UTC-3, Bart wrote:
> On 28/10/2021 16:50, Meredith Montgomery wrote:
> > These seem legal declarations in C:
> >
> > const char msg[9] = "warming:";
> > char const msg[9] = "warming:";
> >
> > What's the difference between them?
> There is no difference. You can even write:
>
> const char const msg[9];
>
>
> 'const' (as well as short, int, long, float, double, even static and
> typedef) can occur anywhere, in any combination, in the declaration of a
> base type (what goes on the left before the first variable).
>
> 'const' can also be repeated any number of times:
>
> char const const const const const const msg[9]

We can also add as many parentheses as we like.
char const const const const const const ((((((msg))))))[9];
:D

Re: on the order of the const-keyword

<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1305:: with SMTP id v5mr7200393qtk.62.1635452302351;
Thu, 28 Oct 2021 13:18:22 -0700 (PDT)
X-Received: by 2002:a37:a3c6:: with SMTP id m189mr5271724qke.233.1635452302137;
Thu, 28 Oct 2021 13:18:22 -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: Thu, 28 Oct 2021 13:18:21 -0700 (PDT)
In-Reply-To: <a25df1f0-687b-4489-8f2f-6daa35593040n@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: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me> <a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
Subject: Re: on the order of the const-keyword
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Thu, 28 Oct 2021 20:18:22 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 42
 by: Thiago Adams - Thu, 28 Oct 2021 20:18 UTC

On Thursday, October 28, 2021 at 4:56:18 PM UTC-3, Thiago Adams wrote:
....
> > 'const' (as well as short, int, long, float, double, even static and
> > typedef) can occur anywhere, in any combination, in the declaration of a
> > base type (what goes on the left before the first variable).

I also have a new definition for typedef considering how it works.

We use to say typedef is a alias for a type name.

But here ,

typedef int Int;
typedef unsigned Int T; //error

Int does not work as a alias for int.

So my definition is:
when we put typedef in a declaration we declare a variable that has no
storage.

When we use this variable is the same of using typeof(variable) but
we write just the variable name.
Int x;
So typedef is more like "use the same type of that variable here".

considering this.... I was also considering to use typedef to define constants

typedef double pi = 3.14;
or
valuedef double pi = 3.14;

pi is a non-storage variable, but instead of copying its type
we copy its initialization value.

double x = pi;

Re: on the order of the const-keyword

<slf1ic$qcv$1@dont-email.me>

  copy mid

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

  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: on the order of the const-keyword
Date: Thu, 28 Oct 2021 21:35:15 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <slf1ic$qcv$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Oct 2021 20:35:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d6027a00a062ce1d57bc54c3c817b675";
logging-data="27039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+GLxZYK8SbmlWEY5GRmDNMui9PSLUiZ8="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:efaHd+JZNLTzPFO3N8+bOBNssso=
In-Reply-To: <994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211028-2, 28/10/2021), Outbound message
 by: Bart - Thu, 28 Oct 2021 20:35 UTC

On 28/10/2021 21:18, Thiago Adams wrote:
> On Thursday, October 28, 2021 at 4:56:18 PM UTC-3, Thiago Adams wrote:
> ...
>>> 'const' (as well as short, int, long, float, double, even static and
>>> typedef) can occur anywhere, in any combination, in the declaration of a
>>> base type (what goes on the left before the first variable).
>
> I also have a new definition for typedef considering how it works.
>
> We use to say typedef is a alias for a type name.
>
> But here ,
>
> typedef int Int;
> typedef unsigned Int T; //error
>
> Int does not work as a alias for int.

I think this is reasonable behavour. To make it work as you want, as an
alias for the 'int' /token/, then it can be done as:

#define Int int

For a composite type like 'int long long', it must be a valid
combination of those tokens. The alias 'T' may be defined internally as
a complete type 'signed long long int'.

You can't then modify it as 'unsigned signed long long int' even if you
could sort out the parsing.

For example, you can't do 'unsigned int32_t'.

>
> So my definition is:
> when we put typedef in a declaration we declare a variable that has no
> storage.

I can never remember how typedef works, and have to pretend that it is
'static', and I'm declaring a normal variable name.

> When we use this variable is the same of using typeof(variable) but
> we write just the variable name.
> Int x;
> So typedef is more like "use the same type of that variable here".
>
> considering this.... I was also considering to use typedef to define constants
>
> typedef double pi = 3.14;
> or
> valuedef double pi = 3.14;
>
> pi is a non-storage variable, but instead of copying its type
> we copy its initialization value.

I tried something like that. I couldn't use 'const' as that was taken; I
used 'constant':

constant int a = 1233;
constant double b = a/10.0;

printf("%d\n", a);
printf("%f\n", b);

This could be tweaked to infer the type from the expression.

Re: on the order of the const-keyword

<7697a67c-fc7e-4b7c-b53f-38076b50cde2n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ae9:ef58:: with SMTP id d85mr5486969qkg.526.1635454651581;
Thu, 28 Oct 2021 13:57:31 -0700 (PDT)
X-Received: by 2002:ac8:42dd:: with SMTP id g29mr7300522qtm.168.1635454651418;
Thu, 28 Oct 2021 13:57:31 -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: Thu, 28 Oct 2021 13:57:31 -0700 (PDT)
In-Reply-To: <slf1ic$qcv$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: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com> <994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
<slf1ic$qcv$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7697a67c-fc7e-4b7c-b53f-38076b50cde2n@googlegroups.com>
Subject: Re: on the order of the const-keyword
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Thu, 28 Oct 2021 20:57:31 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 98
 by: Thiago Adams - Thu, 28 Oct 2021 20:57 UTC

On Thursday, October 28, 2021 at 5:35:36 PM UTC-3, Bart wrote:
> On 28/10/2021 21:18, Thiago Adams wrote:
> > On Thursday, October 28, 2021 at 4:56:18 PM UTC-3, Thiago Adams wrote:
> > ...
> >>> 'const' (as well as short, int, long, float, double, even static and
> >>> typedef) can occur anywhere, in any combination, in the declaration of a
> >>> base type (what goes on the left before the first variable).
> >
> > I also have a new definition for typedef considering how it works.
> >
> > We use to say typedef is a alias for a type name.
> >
> > But here ,
> >
> > typedef int Int;
> > typedef unsigned Int T; //error
> >
> > Int does not work as a alias for int.
> I think this is reasonable behavour. To make it work as you want, as an
> alias for the 'int' /token/, then it can be done as:
>
> #define Int int
>
> For a composite type like 'int long long', it must be a valid
> combination of those tokens. The alias 'T' may be defined internally as
> a complete type 'signed long long int'.
>
> You can't then modify it as 'unsigned signed long long int' even if you
> could sort out the parsing.
>
> For example, you can't do 'unsigned int32_t'.
> >
> > So my definition is:
> > when we put typedef in a declaration we declare a variable that has no
> > storage.
> I can never remember how typedef works, and have to pretend that it is
> 'static', and I'm declaring a normal variable name.
> > When we use this variable is the same of using typeof(variable) but
> > we write just the variable name.
> > Int x;
> > So typedef is more like "use the same type of that variable here".
> >
> > considering this.... I was also considering to use typedef to define constants
> >
> > typedef double pi = 3.14;
> > or
> > valuedef double pi = 3.14;
> >
> > pi is a non-storage variable, but instead of copying its type
> > we copy its initialization value.
> I tried something like that. I couldn't use 'const' as that was taken; I
> used 'constant':
>
> constant int a = 1233;
> constant double b = a/10.0;
>
> printf("%d\n", a);
> printf("%f\n", b);
>
> This could be tweaked to infer the type from the expression.

and because there is no storage we cannot take &a or &b.
BUT I think there is a hidden variable instantiated (just like compound literals)

For instance this is C99.

struct X { int i; };
void F(struct X* x) {}
struct X c = { . i = 1 };
int main() {
F(& (struct X) {.i = 1}); //variable is created
F(&c);
}

in this C99 sample c HAS storage. it exists.
Now lets consider we have this "constant".

struct X { int i; };
void F(struct X* x) {}
constant struct X c = { . i = 1 }; //no storage

int main() {
F(& (struct X) {.i = 1});
F(&c); //what happens here?
}

When we call F(&c) some variable should be instantiated.?

At the end it could work as enumerators work today

enum { A = 1 };
void F(int* i) {}
void F2(int i) {}
int main() {
F(&A); //error: lvalue required as unary '&' operand
F2(A); //OK
}

sometimes a local variable would be created, except for int double etc..

Re: on the order of the const-keyword

<aadf2b60-6c41-434a-8c19-8fc2a60bff15n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:64d4:: with SMTP id y203mr5771494qkb.394.1635455271490;
Thu, 28 Oct 2021 14:07:51 -0700 (PDT)
X-Received: by 2002:a05:622a:50b:: with SMTP id l11mr7265224qtx.415.1635455271319;
Thu, 28 Oct 2021 14:07:51 -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: Thu, 28 Oct 2021 14:07:51 -0700 (PDT)
In-Reply-To: <7697a67c-fc7e-4b7c-b53f-38076b50cde2n@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: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com> <994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
<slf1ic$qcv$1@dont-email.me> <7697a67c-fc7e-4b7c-b53f-38076b50cde2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <aadf2b60-6c41-434a-8c19-8fc2a60bff15n@googlegroups.com>
Subject: Re: on the order of the const-keyword
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Thu, 28 Oct 2021 21:07:51 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 106
 by: Thiago Adams - Thu, 28 Oct 2021 21:07 UTC

On Thursday, October 28, 2021 at 5:57:38 PM UTC-3, Thiago Adams wrote:
> On Thursday, October 28, 2021 at 5:35:36 PM UTC-3, Bart wrote:
> > On 28/10/2021 21:18, Thiago Adams wrote:
> > > On Thursday, October 28, 2021 at 4:56:18 PM UTC-3, Thiago Adams wrote:
> > > ...
> > >>> 'const' (as well as short, int, long, float, double, even static and
> > >>> typedef) can occur anywhere, in any combination, in the declaration of a
> > >>> base type (what goes on the left before the first variable).
> > >
> > > I also have a new definition for typedef considering how it works.
> > >
> > > We use to say typedef is a alias for a type name.
> > >
> > > But here ,
> > >
> > > typedef int Int;
> > > typedef unsigned Int T; //error
> > >
> > > Int does not work as a alias for int.
> > I think this is reasonable behavour. To make it work as you want, as an
> > alias for the 'int' /token/, then it can be done as:
> >
> > #define Int int
> >
> > For a composite type like 'int long long', it must be a valid
> > combination of those tokens. The alias 'T' may be defined internally as
> > a complete type 'signed long long int'.
> >
> > You can't then modify it as 'unsigned signed long long int' even if you
> > could sort out the parsing.
> >
> > For example, you can't do 'unsigned int32_t'.
> > >
> > > So my definition is:
> > > when we put typedef in a declaration we declare a variable that has no
> > > storage.
> > I can never remember how typedef works, and have to pretend that it is
> > 'static', and I'm declaring a normal variable name.
> > > When we use this variable is the same of using typeof(variable) but
> > > we write just the variable name.
> > > Int x;
> > > So typedef is more like "use the same type of that variable here".
> > >
> > > considering this.... I was also considering to use typedef to define constants
> > >
> > > typedef double pi = 3.14;
> > > or
> > > valuedef double pi = 3.14;
> > >
> > > pi is a non-storage variable, but instead of copying its type
> > > we copy its initialization value.
> > I tried something like that. I couldn't use 'const' as that was taken; I
> > used 'constant':
> >
> > constant int a = 1233;
> > constant double b = a/10.0;
> >
> > printf("%d\n", a);
> > printf("%f\n", b);
> >
> > This could be tweaked to infer the type from the expression.
> and because there is no storage we cannot take &a or &b.
> BUT I think there is a hidden variable instantiated (just like compound literals)
>
> For instance this is C99.
>
> struct X { int i; };
> void F(struct X* x) {}
> struct X c = { . i = 1 };
> int main() {
> F(& (struct X) {.i = 1}); //variable is created
> F(&c);
> }
>
> in this C99 sample c HAS storage. it exists.
> Now lets consider we have this "constant".
>
> struct X { int i; };
> void F(struct X* x) {}
> constant struct X c = { . i = 1 }; //no storage
>
> int main() {
> F(& (struct X) {.i = 1});
> F(&c); //what happens here?
> }
>
> When we call F(&c) some variable should be instantiated.?
>
> At the end it could work as enumerators work today
>
> enum { A = 1 };
> void F(int* i) {}
> void F2(int i) {}
> int main() {
> F(&A); //error: lvalue required as unary '&' operand
> F2(A); //OK
> }
>
> sometimes a local variable would be created, except for int double etc..

The reason why this features does not exist today may be because for complex
types we can create a const variable and reuse it.
and use defines for int double etc.

Re: on the order of the const-keyword

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

  copy mid

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

  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: on the order of the const-keyword
Date: Thu, 28 Oct 2021 22:10:45 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <87r1c4voru.fsf@bsb.me.uk>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="58823ca122a82ced16be1e90333a24df";
logging-data="9456"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Pj8Qp6Vq+nGXx+M989Hy3TkqVs3t+348="
Cancel-Lock: sha1:ep4GjPpYsOJigOm7GP3VBqkNMTQ=
sha1:owIpgoHXQV0up3UhPxB4XFZRaMo=
X-BSB-Auth: 1.2e1d17c88d07b9b8f964.20211028221045BST.87r1c4voru.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Oct 2021 21:10 UTC

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

> On Thursday, October 28, 2021 at 4:56:18 PM UTC-3, Thiago Adams wrote:
> ...
>> > 'const' (as well as short, int, long, float, double, even static and
>> > typedef) can occur anywhere, in any combination, in the declaration of a
>> > base type (what goes on the left before the first variable).
>
> I also have a new definition for typedef considering how it works.
>
> We use to say typedef is a alias for a type name.

"We"? The standard doesn't. It says the declaration defines a "typedef
name". I agree it's handy to think of it as an alias, but you have to
take care with analogies in technical situations.

> But here ,
>
> typedef int Int;
> typedef unsigned Int T; //error
>
> Int does not work as a alias for int.

An alias does not work in all contexts. I may be know as Shorty down
the club, but I can't put that on my passport. Sometimes the "proper"
name is needed.

> So my definition is:
> when we put typedef in a declaration we declare a variable that has no
> storage.

Well typedef is, syntactically, a storage class specifier like extern,
static and register, so I can see why you might prefer that analogy.

--
Ben.

Re: on the order of the const-keyword

<slf67a$pu0$1@dont-email.me>

  copy mid

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

  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: on the order of the const-keyword
Date: Thu, 28 Oct 2021 22:54:40 +0100
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <slf67a$pu0$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
<slf1ic$qcv$1@dont-email.me>
<7697a67c-fc7e-4b7c-b53f-38076b50cde2n@googlegroups.com>
<aadf2b60-6c41-434a-8c19-8fc2a60bff15n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Oct 2021 21:54:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d6027a00a062ce1d57bc54c3c817b675";
logging-data="26560"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BSKvYqsD+pjWvKmQQXeQV6OD2aMR/aT8="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:A30JZt426w737/M2g9H/ONnE9DI=
In-Reply-To: <aadf2b60-6c41-434a-8c19-8fc2a60bff15n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211028-2, 28/10/2021), Outbound message
 by: Bart - Thu, 28 Oct 2021 21:54 UTC

On 28/10/2021 22:07, Thiago Adams wrote:
> On Thursday, October 28, 2021 at 5:57:38 PM UTC-3, Thiago Adams wrote:

>> in this C99 sample c HAS storage. it exists.
>> Now lets consider we have this "constant".
>>
>> struct X { int i; };
>> void F(struct X* x) {}
>> constant struct X c = { . i = 1 }; //no storage
>>
>> int main() {
>> F(& (struct X) {.i = 1});
>> F(&c); //what happens here?
>> }
>>
>> When we call F(&c) some variable should be instantiated.?
>>
>> At the end it could work as enumerators work today
>>
>> enum { A = 1 };
>> void F(int* i) {}
>> void F2(int i) {}
>> int main() {
>> F(&A); //error: lvalue required as unary '&' operand
>> F2(A); //OK
>> }
>>
>> sometimes a local variable would be created, except for int double etc..
>
> The reason why this features does not exist today may be because for complex
> types we can create a const variable and reuse it.
> and use defines for int double etc.

Below is a summary, in the first 3 Y/N columns, of the three different
ways C has to create named constants.

It's set up so that a Y response is the more desirable.

Here, enums tick nearly all the boxes, so that it is odd that #define
and const T seem more popular. But then, 'enum' was really intended for
other purposes (defining related names with incrementing values), so it
might itself seem odd to use it arbitrarily.

My 'constant' feature ticks all the boxes plus it doesn't look weird to use.

Characteristic #define const T enum 'constant'

Normal scope? N Y Y Y
Any numeric type? Y Y N Y
Avoids storage (5) Y N (3) Y Y
Use in non-VLA bounds Y N Y Y
Won't create a VLA? Y N Y Y
Use in static array bounds Y N Y Y
Use in switch-case labels Y N Y Y
Evaluate once (1) N Y Y Y
Prohibit & address-of Y N Y Y
Prohibit Pass by ref Y N Y Y
Impossible to modify? Y N (2) Y Y
Reduce const exprs? Y ? (3) Y Y
Unambiguous meaning (4) N Y Y Y

(1) With #define A ((B+C)*D) etc, at each place A is used, it will
expand that expression, and need to parse it and reduce, possibly 100s
of times

(2) It's possible to modify via casts

(3) Depends on compiler's optimisation abilities

(4) With #define, using the same ((B+C)*D) example each time A is
expanded, it will use whatever B, C, D names are in scope at that point,
potentially generating a different value of A each time.

(5) Apart from immediate operands, some hardware may require storage
for certain float operands for example. But this is not accessible to C
programs.

Re: on the order of the const-keyword

<87a6is23xa.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Thu, 28 Oct 2021 15:13:53 -0700
Organization: None to speak of
Lines: 61
Message-ID: <87a6is23xa.fsf@nosuchdomain.example.com>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="d19e72ac6c40f753288e1cb579e60581";
logging-data="31975"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18g/orxFtJunqvg3bCV4ELE"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:/vo+YUhd67Z0sXIEY1jjt6nbKgI=
sha1:8axksJND9zVU3cjcIUdQ2lcmhWY=
 by: Keith Thompson - Thu, 28 Oct 2021 22:13 UTC

Thiago Adams <thiago.adams@gmail.com> writes:
> On Thursday, October 28, 2021 at 4:56:18 PM UTC-3, Thiago Adams wrote:
> ...
>> > 'const' (as well as short, int, long, float, double, even static and
>> > typedef) can occur anywhere, in any combination, in the declaration of a
>> > base type (what goes on the left before the first variable).
>
> I also have a new definition for typedef considering how it works.
>
> We use to say typedef is a alias for a type name.
>
> But here ,
>
> typedef int Int;
> typedef unsigned Int T; //error
>
> Int does not work as a alias for int.

Yes, it absolutely does. Given your first declaration, `Int` is an
alias for the *type* `int`, not for the *keyword* `int`. It's not a
macro, and it doesn't act like one.

The `unsigned` keyword can only be used as the syntax allows, and the
syntax doesn't allow it to be used with a typedef name. The `unsigned`
keyword can be used by itself as a type name, or along with the `char`,
`short`, `int`, and/or `long` keywords, as defined in N1570 6.7.2.

> So my definition is:
> when we put typedef in a declaration we declare a variable that has no
> storage.

No, that's not what it does. It doesn't declare a variable at all, with
or without storage, unless you stretch the meaning of "variable" almost
beyond recognition. (Note that the C standard doesn't use the term
"variable".). Rather, the `typedef` keyword is treated as a storage
class specifier for syntactic convenience.

> When we use this variable is the same of using typeof(variable) but
> we write just the variable name.
> Int x;
> So typedef is more like "use the same type of that variable here".
>
> considering this.... I was also considering to use typedef to define constants
>
> typedef double pi = 3.14;
> or
> valuedef double pi = 3.14;
>
> pi is a non-storage variable, but instead of copying its type
> we copy its initialization value.
>
> double x = pi;

That's more or less what `constexpr` does in C++, and what `const`
*almost* does in C. Using `typedef` for this would not in my opinion
make sense.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: on the order of the const-keyword

<875ytg22ty.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Thu, 28 Oct 2021 15:37:29 -0700
Organization: None to speak of
Lines: 52
Message-ID: <875ytg22ty.fsf@nosuchdomain.example.com>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
<slf1ic$qcv$1@dont-email.me>
<7697a67c-fc7e-4b7c-b53f-38076b50cde2n@googlegroups.com>
<aadf2b60-6c41-434a-8c19-8fc2a60bff15n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="d19e72ac6c40f753288e1cb579e60581";
logging-data="31975"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18quw4PtG9YRGpsSMS0BA0/"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:mux1NQjcEDCux2851hSRQSqVkCk=
sha1:nqrz8PXmDUcP91C3pep+DOiicng=
 by: Keith Thompson - Thu, 28 Oct 2021 22:37 UTC

Thiago Adams <thiago.adams@gmail.com> writes:
> On Thursday, October 28, 2021 at 5:57:38 PM UTC-3, Thiago Adams wrote:
[...]
>> At the end it could work as enumerators work today
>>
>> enum { A = 1 };
>> void F(int* i) {}
>> void F2(int i) {}
>> int main() {
>> F(&A); //error: lvalue required as unary '&' operand
>> F2(A); //OK
>> }
>>
>> sometimes a local variable would be created, except for int double etc..
>
> The reason why this features does not exist today may be because for complex
> types we can create a const variable and reuse it.
> and use defines for int double etc.

C's "const" keyword does not mean "constant", and it never has. Of
course the spelling is derived from the English word "constant", which
can cause some understandable confusion.

A *constant expression* is one that can be evaluated at compile time.
A *constant* is a literal.

The keyword "const" might more accurately have been spelled "readonly".
If a name is const-qualified, it means that the named object cannot be
modified via that name. Defining something as "const" never makes
its name a constant expression.

C++ added a special case, so that for example
const int n = 42;
makes the expression n a constant expression (though n is still an
object whose address can be taken). Later, C++ added the "constexpr"
keyword (like "const" but it requires the initializer to be constant),
which in my opinion would have been a better choice for this special
case.

Note that this:
const time_t now = time(NULL);
is perfectly legal; the expression t cannot even in principle be
evaluated at compile time. (`constexpr time_t now = time(NULL);`
is invalid in C++.)

I wouldn't mind seeing a future version of C adopt something like C++'s
"constexpr" -- *without* changing the current meaning of "const".

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: on the order of the const-keyword

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

  copy mid

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

  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: on the order of the const-keyword
Date: Fri, 29 Oct 2021 00:02:13 +0100
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <87lf2cvjm2.fsf@bsb.me.uk>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
<slf1ic$qcv$1@dont-email.me>
<7697a67c-fc7e-4b7c-b53f-38076b50cde2n@googlegroups.com>
<aadf2b60-6c41-434a-8c19-8fc2a60bff15n@googlegroups.com>
<875ytg22ty.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="e05153e92b9fdefa3c118fcfe9e0c770";
logging-data="2423"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yOFN89BP08Pj6VCjvAbyXqMNccccl4is="
Cancel-Lock: sha1:VFZq0XnHy3T7622JqWoCWcqqdEs=
sha1:OsSJwsXmXaD7HHHWsZIqH0FS6QE=
X-BSB-Auth: 1.3feb693962de95711d87.20211029000213BST.87lf2cvjm2.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Oct 2021 23:02 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> I wouldn't mind seeing a future version of C adopt something like C++'s
> "constexpr" -- *without* changing the current meaning of "const".

It's been proposed:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2851.pdf

--
Ben.

Re: on the order of the const-keyword

<86h7d0mtqp.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!EKCVjuy47ovTI5d14PUybA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Thu, 28 Oct 2021 23:48:14 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86h7d0mtqp.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="12659"; posting-host="EKCVjuy47ovTI5d14PUybA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:cgi8nJQbKwhvG+zk+thphBpDOx4=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 29 Oct 2021 02:48 UTC

Bart <bc@freeuk.com> writes:

> On 28/10/2021 16:50, Meredith Montgomery wrote:
>> These seem legal declarations in C:
>> const char msg[9] = "warming:";
>> char const msg[9] = "warming:";
>> What's the difference between them?
>
> There is no difference. You can even write:
>
> const char const msg[9];
>
>
> 'const' (as well as short, int, long, float, double, even static and
> typedef) can occur anywhere, in any combination, in the declaration of
> a base type (what goes on the left before the first variable).
>
> 'const' can also be repeated any number of times:
>
> char const const const const const const msg[9]
>
> if you want to be certain that msg is constant!
>
> However when applied to a pointer, then it must go after *.

Very interesting. Thank you so much for this.

Re: on the order of the const-keyword

<86y26cle9j.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!EKCVjuy47ovTI5d14PUybA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Fri, 29 Oct 2021 00:07:52 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86y26cle9j.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<2a5589c2-89ac-4d77-a91d-508c00f75e43n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="23465"; posting-host="EKCVjuy47ovTI5d14PUybA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:aATzWEP1kL0pA8lLd1P7Y9eAO7k=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 29 Oct 2021 03:07 UTC

"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> writes:

> On Thursday, October 28, 2021 at 12:26:09 PM UTC-4, Bart wrote:
> ...
>> 'const' (as well as short, int, long, float, double, even static and
>> typedef) can occur anywhere, in any combination, in the declaration of a
>> base type (what goes on the left before the first variable).
> ...
>> However when applied to a pointer, then it must go after *.
>
> const char * p
> char * const q;
> char const * const r;
>
> are all permitted. p is a pointer to const char. q is a const pointer
> to char. r is a const pointer to const char.

So the order does make a difference here. I mean

char const * r1

is not the same

char const * const r2

because r2 cannot point somewhere else but r1 can.

Thank you.

(*) So, I wrote this to check

#include <stdio.h>

int main()
{ const char c1 = 'x';
const char c2 = 'y';

const char* r1 = &c1;
const char* const r2 = &c1;

printf("r1 = %c, r2 = %c\n", *r1, *r2);

r1 = &c2;
/* r2 = &c2; */ /* cant do this */
printf("r1 = %c, r2 = %c\n", *r1, *r2);

return 0;
}

(*) What have I learned here as well?

When we declare something to be const we also have to define it in the
statement. IOW, I cannot separate declaration and definition of a const
thing. This makes sense --- if I can assign a const-thing, how would
the compiler keep me from changing it? (But it wasn't clear to me 'til
now.)

Re: on the order of the const-keyword

<86sfwkld1p.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!EKCVjuy47ovTI5d14PUybA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Fri, 29 Oct 2021 00:34:10 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86sfwkld1p.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <slel67$ppc$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="36252"; posting-host="EKCVjuy47ovTI5d14PUybA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:+D15ZOverKjs6pUxXnF2PXABOWo=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 29 Oct 2021 03:34 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 10/28/21 11:50 AM, Meredith Montgomery wrote:
>> These seem legal declarations in C:
>>
>> const char msg[9] = "warming:";
>> char const msg[9] = "warming:";
>>
>> What's the difference between them?
>>
>> (*) Note to self
>>
>> When I tried changing that array, the compiler did not let me to ---
>> with either declaration. (So it appears there is no *effective*
>> difference.)
>>
>> %cat msg.c
>> #include <stdio.h>
>>
>> int main(void) {
>>
>> char const msg[9] = "warming:";
>> msg[0]= 'f';
>> printf("%s\n", msg);
>>
>> }
>> %make msg
>> gcc msg.c -o msg
>> msg.c: In function 'main':
>> msg.c:6:9: error: assignment of read-only location 'msg[0]'
>> 6 | msg[0]= 'f';
>> | ^
>> make: *** [<builtin>: msg] Error 1
>> %
>>
>
> "const" is a type qualifier. "char" is a type specifier. Both are
> members of the larger category called "declaration specifiers". If you
> have a string of declaration specifiers, they can occur in any order you
> like, without any change of meaning.

That's a nice description. Thank you. I'm making the following
parallel in my mind:

type qualifier /is like/ an adjective
type specifier /is like/ a noun

(``Let c be /char/ming, but qualify it as unmovable.'')

Re: on the order of the const-keyword

<86ilxglcqj.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!aioe.org!EKCVjuy47ovTI5d14PUybA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Fri, 29 Oct 2021 00:40:52 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86ilxglcqj.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<a25df1f0-687b-4489-8f2f-6daa35593040n@googlegroups.com>
<994066a9-5940-4d1c-8df4-517905174930n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="39249"; posting-host="EKCVjuy47ovTI5d14PUybA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:EGkLkxnBWS2PwtE4Y9Pey2wNRvE=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 29 Oct 2021 03:40 UTC

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

[...]

> So my definition is: when we put typedef in a declaration we declare a
> variable that has no storage.

I don't like to say a variable that has no storage. Even the literal
constants written in the body of your programs are loaded in memory and
the place they occupy *is* storage.

Of course, the whole idea that numbers represent themselves (and the
fact that in languages like C we cannot get the address of literal
number) encourages us to think like you do above, but I think that's not
a very good idea.

Re: on the order of the const-keyword

<slfuf4$p46$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Fri, 29 Oct 2021 00:48:36 -0400
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <slfuf4$p46$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <sleiul$8m0$1@dont-email.me>
<2a5589c2-89ac-4d77-a91d-508c00f75e43n@googlegroups.com>
<86y26cle9j.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Oct 2021 04:48:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="231fd31b05a5419972995c708529a10b";
logging-data="25734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183t9RUsJpdp17GrO6zrL/HLjw83RSA/Jo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:8pKTJjciFhAuNHe+oRKOCPzny9w=
In-Reply-To: <86y26cle9j.fsf@levado.to>
Content-Language: en-US
 by: James Kuyper - Fri, 29 Oct 2021 04:48 UTC

On 10/28/21 11:07 PM, Meredith Montgomery wrote:
> "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> writes:
>
>> On Thursday, October 28, 2021 at 12:26:09 PM UTC-4, Bart wrote:
>> ...
>>> 'const' (as well as short, int, long, float, double, even static and
>>> typedef) can occur anywhere, in any combination, in the declaration of a
>>> base type (what goes on the left before the first variable).
>> ...
>>> However when applied to a pointer, then it must go after *.
>>
>> const char * p
>> char * const q;
>> char const * const r;
>>
>> are all permitted. p is a pointer to const char. q is a const pointer
>> to char. r is a const pointer to const char.
>
> So the order does make a difference here. I mean
>
> char const * r1
>
> is not the same
>
> char const * const r2
>
> because r2 cannot point somewhere else but r1 can.
>
> Thank you.

The top-level grammar for such a declaration is

declaration-specifiers init-declarator-list opt ;

"char const" are the declaration specifiers, while the
init-declarator-list consists of a single declarator with no
initializer, which is "* const r2". "r2" is the identifier being
declared, and after any "*" in a declarator there may be additional type
qualifiers that are not part of the initial list of declaration
specifiers. Unlike the order of the declaration specifiers, the order of
the type qualifiers relative to the "*"s is VERY important.

Re: on the order of the const-keyword

<slg9ru$nmg$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Fri, 29 Oct 2021 10:03:09 +0200
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <slg9ru$nmg$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Oct 2021 08:03:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="044730f83b8df4b517f7b640a2035a1b";
logging-data="24272"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FFJHwz/ZPyyVzg5x9aQo5V1S2gOOY0q4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:8AZP0Klz9iQYf1kkw2pQOajbyRE=
In-Reply-To: <86mtmtm9m1.fsf@levado.to>
Content-Language: en-GB
 by: David Brown - Fri, 29 Oct 2021 08:03 UTC

On 28/10/2021 17:50, Meredith Montgomery wrote:
> These seem legal declarations in C:
>
> const char msg[9] = "warming:";
> char const msg[9] = "warming:";
>
> What's the difference between them?
>

Nothing.

Both mean that the array is made of "const char" elements - after you
have initialised the array, you can't change them.

A lot of people prefer the "const on the left" arrangement :

const int x = 123;

It is very common to use this ordering - many programmers feel it is
more natural.

Some people prefer the "const on the right" arrangement (known as "east
const") :

int const x = 123;

The argument there is that it is more consistent, especially in C++
(which has a few other possible uses of the word "const").

It is fair to say that the "east const" is more consistent when you have
more complicated declarations involving pointers with "const" applied to
different parts. That does not mean that it is the clearest way to
write simple declarations, which are far more common. So opinions
differ here. You have to learn to understand the placement options as
you will see both when you read other people's code, and you have to
decide for yourself which you choose in your own code (unless you are
using a set of style guidelines that forces the decision on you).

The general rule is "const applies to the thing just to the left of it,
unless there is nothing to the left of it and it then applies to the
thing to the right of it". This fits well with the usual best tactic
for parsing most types - start from the right and work left.

Re: on the order of the const-keyword

<slgigl$pss$1@dont-email.me>

  copy mid

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

  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: on the order of the const-keyword
Date: Fri, 29 Oct 2021 11:30:34 +0100
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <slgigl$pss$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Oct 2021 10:30:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4dfa5497c35af60b32b6e19e9e516634";
logging-data="26524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/chgrQ781zhsj5q2MwaE4O4Jh2pebPi94="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Dy2aQbrl3vxs6JWa1GGuOPhRYMg=
In-Reply-To: <slg9ru$nmg$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211029-0, 29/10/2021), Outbound message
 by: Bart - Fri, 29 Oct 2021 10:30 UTC

On 29/10/2021 09:03, David Brown wrote:
> On 28/10/2021 17:50, Meredith Montgomery wrote:
>> These seem legal declarations in C:
>>
>> const char msg[9] = "warming:";
>> char const msg[9] = "warming:";
>>
>> What's the difference between them?

> The general rule is "const applies to the thing just to the left of it,
> unless there is nothing to the left of it and it then applies to the
> thing to the right of it".
The trouble is the 'thing' will be just a token, not a complete type, so
here:

long const long x;

const applies neither to the first long nor the second, but to the
complete type 'long long'. It's in the middle!

This is interesting as there are now three placements for 'const' rather
than two. As well, of course, as any combination of all three:

const int const unsigned const long const long const x;

All you can really advise is:

* Identify the base type: the part before you get to the bit that
marks the end of the base type, any of: variable/function/param name, (,
*, comma or ).

* If there is at least one const anywhere in that base type, then the
whole base type is const.

> This fits well with the usual best tactic
> for parsing most types - start from the right and work left.

Yeah, so the type of 'c' here:

int *a(void), *b[77], (*c)[5][10];

according to your method, is:

array 10 of array 5 of pointer to (skipping a/b modifiers) int

The actual type is:

pointer to array 5 of array 10 of int

Which is pretty much the opposite!

Re: on the order of the const-keyword

<slh0j8$26m$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Fri, 29 Oct 2021 16:31:04 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <slh0j8$26m$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Oct 2021 14:31:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="044730f83b8df4b517f7b640a2035a1b";
logging-data="2262"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IdDpOaA7BM3Pvi4IWX8yaM/sgiuSMI2E="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:vosg9d7dFs0v5R+aIGYtTbwTVxk=
In-Reply-To: <slgigl$pss$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 29 Oct 2021 14:31 UTC

On 29/10/2021 12:30, Bart wrote:
> On 29/10/2021 09:03, David Brown wrote:
>> On 28/10/2021 17:50, Meredith Montgomery wrote:
>>> These seem legal declarations in C:
>>>
>>>    const char msg[9] = "warming:";
>>>    char const msg[9] = "warming:";
>>>
>>> What's the difference between them?
>
>> The general rule is "const applies to the thing just to the left of it,
>> unless there is nothing to the left of it and it then applies to the
>> thing to the right of it".
> The trouble is the 'thing' will be just a token, not a complete type, so
> here:
>
>    long const long x;

And how /exactly/ do you think this kind of thing is helping someone
learning the language? No one writes code like that, so it is simply
not an issue. If you are writing a compiler and want to be sure it is
as standards-compliant as you can, you need to know about this sort of
thing - no one else does.

You seem to have an irresistible urge to spread your own confusions, and
to highlight the worst possible complications of the language. It is as
unhelpful for a poster like this OP as those who quote the details of
standards, or go off on tangents about how they want to add weird
extensions to their own compilers. How about just giving the guy some
useful advice and general rules, rather than every obscure exception to
those rules?

This thread (not just your replies, but those from several others) is
why comp.lang.c has a reputation for being useless to people looking for
help with the C language.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor