Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Imitation is the sincerest form of plagiarism.


devel / comp.lang.c / Re: 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
Re: on the order of the const-keyword

<86lf2bj1pj.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Hu1f/gStftKYRp2bwzXADg.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 12:22:00 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86lf2bj1pj.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="14259"; posting-host="Hu1f/gStftKYRp2bwzXADg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:IqswdSgQ6xqEp3comNvNiRhcNYY=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 29 Oct 2021 15:22 UTC

David Brown <david.brown@hesbynett.no> writes:

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

Pretty useful guidance. Thank you. I will try that from now on.

You spoke of consistency above, but your paragraphs sometimes skip one
line, sometimes two lines, sometimes three lines. What's up with that?

:-)

Re: on the order of the const-keyword

<slh4vq$neb$1@dont-email.me>

  copy mid

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

  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 16:45:51 +0100
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <slh4vq$neb$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me> <slh0j8$26m$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Oct 2021 15:46:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4dfa5497c35af60b32b6e19e9e516634";
logging-data="24011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BIUMU4475vwz+EXikkBR+cKEBnb/S4Tw="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:LAzuhzBmuml9DXVO3qXvm+aW8dc=
In-Reply-To: <slh0j8$26m$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211029-2, 29/10/2021), Outbound message
 by: Bart - Fri, 29 Oct 2021 15:45 UTC

On 29/10/2021 15:31, David Brown wrote:
> 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.

They presumably do do so (even if it's indirectly via macros), otherwise
most alternatives for writing the same type would long have been
deprecated from the language, with tighter rules as to the placement and
number of 'const' attributes.

> If you are writing a compiler and want to be sure it is
> as standards-compliant as you can,

Think about why that might be necessary.

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

I like to give the unadorned facts. Have a look at my first post again.
I say exactly what C allows you to write. Knowing that type declarations
can be a free-for-all is handy when encountering anything unusual.

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

Your advice to read declarations from right to left I think was not
helpful either, being incorrect except in the simplest cases involving
only * modifiers and associated consts.

Re: on the order of the const-keyword

<slh7j5$ohl$1@dont-email.me>

  copy mid

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

  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 18:30:28 +0200
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <slh7j5$ohl$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me> <slh0j8$26m$1@dont-email.me>
<slh4vq$neb$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 16:30:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="48125b5bba22f5603198625e87a36717";
logging-data="25141"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18oL+MfJwcFPi4q+hlpBYV6lOdmBHNAs5M="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:ZfCpkY7QkNBUtmD/KBbR8nzR28o=
In-Reply-To: <slh4vq$neb$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 29 Oct 2021 16:30 UTC

On 29/10/2021 17:45, Bart wrote:
> On 29/10/2021 15:31, David Brown wrote:
>> 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.
>
> They presumably do do so (even if it's indirectly via macros), otherwise
> most alternatives for writing the same type would long have been
> deprecated from the language, with tighter rules as to the placement and
> number of 'const' attributes.
>

Why? What would be the advantages of deprecating it? It would make no
difference to people writing C, but mean extra checks would have to be
added to compliant compilers as well as changes to the grammar in the
standards document. And there may conceivably be some odd program with
code like this - perhaps something with a history so far back that it
used macros instead of typedefs and ended up with such results. All in
all, making such changes would be all effort and no gain.

>> If you are writing a compiler and want to be sure it is
>> as standards-compliant as you can,
>
> Think about why that might be necessary.
>
>> 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,
>
> I like to give the unadorned facts. Have a look at my first post again.
> I say exactly what C allows you to write. Knowing that type declarations
> can be a free-for-all is handy when encountering anything unusual.
>
>> 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.
>
> Your advice to read declarations from right to left I think was not
> helpful either, being incorrect except in the simplest cases involving
> only * modifiers and associated consts.
>

In other words, it applies fine to the large majority of declarations.
You can add "inside out" to it to cover more cases.

I understand that this is a simplification - but that's what people need
at the start.

Re: on the order of the const-keyword

<slh7rf$qai$1@dont-email.me>

  copy mid

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

  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 18:34:55 +0200
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <slh7rf$qai$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<86lf2bj1pj.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Oct 2021 16:34:55 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="48125b5bba22f5603198625e87a36717";
logging-data="26962"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fHz/FFgaakQk0rWGqo8jBYuPMMpLdNjM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:q0uF978hO0Y1W8kQcVVaPtbLWhs=
In-Reply-To: <86lf2bj1pj.fsf@levado.to>
Content-Language: en-GB
 by: David Brown - Fri, 29 Oct 2021 16:34 UTC

On 29/10/2021 17:22, Meredith Montgomery wrote:
> David Brown <david.brown@hesbynett.no> writes:
>
>> 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.
>
> Pretty useful guidance. Thank you. I will try that from now on.
>
> You spoke of consistency above, but your paragraphs sometimes skip one
> line, sometimes two lines, sometimes three lines. What's up with that?
>
> :-)
>

It's to give you time to think and absorb the information underway!
Also, it gives a visual separation that is greater than I used for the
code snippets - so the spacing is intentional. (I know your question
wasn't very serious.)

Re: on the order of the const-keyword

<86ilxfha1n.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Hu1f/gStftKYRp2bwzXADg.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 17:04:52 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86ilxfha1n.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<86lf2bj1pj.fsf@levado.to> <slh7rf$qai$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="18655"; posting-host="Hu1f/gStftKYRp2bwzXADg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:vH4uEEVZr8ItMEFV4Fm1J4GW+5c=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 29 Oct 2021 20:04 UTC

David Brown <david.brown@hesbynett.no> writes:

> On 29/10/2021 17:22, Meredith Montgomery wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>
>>> 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.
>>
>> Pretty useful guidance. Thank you. I will try that from now on.
>>
>> You spoke of consistency above, but your paragraphs sometimes skip one
>> line, sometimes two lines, sometimes three lines. What's up with that?
>>
>> :-)
>>
>
> It's to give you time to think and absorb the information underway!
> Also, it gives a visual separation that is greater than I used for the
> code snippets - so the spacing is intentional. (I know your question
> wasn't very serious.)

It wasn't, yes, but that's because I thought there wasn't a special
reason. Now that I know there is, I'm impressed and a bit surprised, so
now I'm glad I asked.

Here's what I probably would have done.

--8<---------------cut here---------------start------------->8---
(*) Introduction

Lorem ipsum dolor...

(*) Now to your question specifically

Lorem...

(*) Taking stock or something

Lorem ipsum...
--8<---------------cut here---------------end--------------->8---

If you think about it, your style up there is a a bit too implicit. If
I'd like to give the reader some time to ponder, I would say that
explicitly --- dear reader, please take some time to ponder.

Having said that, I never cast the return of malloc. :-)

Re: on the order of the const-keyword

<slhspd$1rjm$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: on the order of the const-keyword
Date: Sat, 30 Oct 2021 00:32:13 +0200
Organization: Aioe.org NNTP Server
Message-ID: <slhspd$1rjm$1@gioia.aioe.org>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me> <slh0j8$26m$1@dont-email.me>
<slh4vq$neb$1@dont-email.me> <slh7j5$ohl$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="61046"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.2.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Fri, 29 Oct 2021 22:32 UTC

On 10/29/2021 6:30 PM, David Brown wrote:
> On 29/10/2021 17:45, Bart wrote:
>> On 29/10/2021 15:31, David Brown wrote:
>>> 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.
>>
>> They presumably do do so (even if it's indirectly via macros), otherwise
>> most alternatives for writing the same type would long have been
>> deprecated from the language, with tighter rules as to the placement and
>> number of 'const' attributes.
>>
>
> Why? What would be the advantages of deprecating it? It would make no
> difference to people writing C, but mean extra checks would have to be
> added to compliant compilers as well as changes to the grammar in the
> standards document. And there may conceivably be some odd program with
> code like this - perhaps something with a history so far back that it
> used macros instead of typedefs and ended up with such results. All in
> all, making such changes would be all effort and no gain.
>
>>> If you are writing a compiler and want to be sure it is
>>> as standards-compliant as you can,
>>
>> Think about why that might be necessary.
>>
>>> 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,
>>
>> I like to give the unadorned facts. Have a look at my first post again.
>> I say exactly what C allows you to write. Knowing that type declarations
>> can be a free-for-all is handy when encountering anything unusual.
>>
>>> 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.
>>
>> Your advice to read declarations from right to left I think was not
>> helpful either, being incorrect except in the simplest cases involving
>> only * modifiers and associated consts.
>>
>
> In other words, it applies fine to the large majority of declarations.
> You can add "inside out" to it to cover more cases.
>
> I understand that this is a simplification - but that's what people need
> at the start.
>
>
>

Not sure about that, at least not this kind of simplification.
I think Bart made a good point, in noting that the right-to-left rule
does not work well in some case, notably with pointers to arrays, which
is something to be considered at any level of C knowledge.
So, as a first a simplification that can be wrong with some declaration
that, although unfriendly to the novice, can actually be found in real
code, runs the risk of being more confusing than helpful for the less
experienced.
The second problem is that when such less experienced happens to read
the standard's definition (which will happen at some point for any
serious programmer), they will have the problem that the simplification
is nowhere near the wording of the standard, so again risk of more
confusion than help.

From all the answers that have been given here, I think that one of
James Kuypers' (the one citing the standard's distinction between
'declaration-specifiers' and 'init-declarator-list') is the most useful,
because /that/ is how declarations work in C, plain and simple, even if
their description is not that simple.

Re: on the order of the const-keyword

<slhtss$636$1@dont-email.me>

  copy mid

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

  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 23:51:07 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <slhtss$636$1@dont-email.me>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me> <slh0j8$26m$1@dont-email.me>
<slh4vq$neb$1@dont-email.me> <slh7j5$ohl$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 22:51:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1e5cb410d6b3762b4b6665d5b1b0a87e";
logging-data="6246"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fe/pQejnt0jI+f5O8OaK5V1AnaPy2pWA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.2.1
Cancel-Lock: sha1:EmsXlgQYHH3hLhhc24qB1Qvczco=
In-Reply-To: <slh7j5$ohl$1@dont-email.me>
 by: Bart - Fri, 29 Oct 2021 22:51 UTC

On 29/10/2021 17:30, David Brown wrote:
> On 29/10/2021 17:45, Bart wrote:

>> They presumably do do so (even if it's indirectly via macros), otherwise
>> most alternatives for writing the same type would long have been
>> deprecated from the language, with tighter rules as to the placement and
>> number of 'const' attributes.
>>
>
> Why? What would be the advantages of deprecating it? It would make no
> difference to people writing C, but mean extra checks would have to be
> added to compliant compilers as well as changes to the grammar in the
> standards document.

It actually makes compilation simpler, if you knew for example that the
pattern was always:

[const] [unsigned/signed] [long [long] / short] int

As to the advantages of deprecating it, the behaviour of most compilers,
using default options, is to be incredibly lax about things that I
consider irresponsibly dangerous.

So people continue their bad coding habits, because they are not like
you in devising a strict dialect of the language, and implementing that
dialect via sets of compiler options.

> And there may conceivably be some odd program with
> code like this

Or maybe you write the code by accident. Then you are either puzzled why
it doesn't work, or don't notice, until it puzzles someone else.

- perhaps something with a history so far back that it
> used macros instead of typedefs and ended up with such results. All in
> all, making such changes would be all effort and no gain.

It can be easier than you think. My own compiler disallows many things I
consider unacceptable. But for the purposes of compiling legacy code, I
require one special option to be specified.

Re: on the order of the const-keyword

<86sfwje8mt.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!aioe.org!Hu1f/gStftKYRp2bwzXADg.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 20:03:38 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86sfwje8mt.fsf@levado.to>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me> <slh0j8$26m$1@dont-email.me>
<slh4vq$neb$1@dont-email.me> <slh7j5$ohl$1@dont-email.me>
<slhspd$1rjm$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="17019"; posting-host="Hu1f/gStftKYRp2bwzXADg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:CVlSWhc9LqbjIIt7dIWuDe3T7eQ=
 by: Meredith Montgomery - Fri, 29 Oct 2021 23:03 UTC

Manfred <noname@add.invalid> writes:

> On 10/29/2021 6:30 PM, David Brown wrote:
>> On 29/10/2021 17:45, Bart wrote:
>>> On 29/10/2021 15:31, David Brown wrote:
>>>> 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?

[...]

>>> Your advice to read declarations from right to left I think was not
>>> helpful either, being incorrect except in the simplest cases involving
>>> only * modifiers and associated consts.
>>>
>> In other words, it applies fine to the large majority of
>> declarations. You can add "inside out" to it to cover more cases. I
>> understand that this is a simplification - but that's what people
>> need at the start.
>
> Not sure about that, at least not this kind of simplification. I
> think Bart made a good point, in noting that the right-to-left rule
> does not work well in some case, notably with pointers to arrays,
> which is something to be considered at any level of C knowledge. So,
> as a first a simplification that can be wrong with some declaration
> that, although unfriendly to the novice, can actually be found in real
> code, runs the risk of being more confusing than helpful for the less
> experienced.
>
> The second problem is that when such less experienced happens to read
> the standard's definition (which will happen at some point for any
> serious programmer), they will have the problem that the
> simplification is nowhere near the wording of the standard, so again
> risk of more confusion than help.
>
> From all the answers that have been given here, I think that one of
> James Kuypers' (the one citing the standard's distinction between
> 'declaration-specifiers' and 'init-declarator-list') is the most
> useful, because /that/ is how declarations work in C, plain and
> simple, even if their description is not that simple.

It's really education we're talking about here. Education is not quite
a scientific area; it's a philosophical one in the Bertrand Russell
sense of philosophy: if there were a clear answer to how to do it, it'd
be called science. (See the first few pages of his ``A History of
Western Philosophy''.)

Because we don't know what is the right approach, we should more or less
provide them all. More or less, of course. And it is a very good idea
to present to students your opinion such as --- this is the right
approach **for sure** and there are other silly approaches too because
some people are too blind to see.

Consider this very thread. A novice is looking at this and getting a
clear picture of the cloud that education in this area is. (It's like
that in every area, actually.) That's (evidently) a fact --- locally at
the very least.

One of the great friends of students is moving-ahead. You realize
you've got an education when you look back, but to look back you must
move ahead. So it is a good idea to come up with a modus operandi, even
if it's broken. This is an important piece of the scientific method:
come up with a hypothesis and stress it until it breaks.

But, of course, if the student can't understand the hypothesis (because
it's too complex), then it might be a useless one. There are multiple
levels of students --- there are researcher-students, students-students,
children-students.

Re: on the order of the const-keyword

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

  copy mid

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

  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: Sat, 30 Oct 2021 01:10:01 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <87sfwjtlt2.fsf@bsb.me.uk>
References: <86mtmtm9m1.fsf@levado.to> <slg9ru$nmg$1@dont-email.me>
<slgigl$pss$1@dont-email.me> <slh0j8$26m$1@dont-email.me>
<slh4vq$neb$1@dont-email.me> <slh7j5$ohl$1@dont-email.me>
<slhspd$1rjm$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="bed14636410651230bd102096cdcac7d";
logging-data="30465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hkwdjV5vGNuKH1fPoiHjHMKxchSNHRus="
Cancel-Lock: sha1:PbXlyZ6H0baZBRt12yMbJUQOgQ4=
sha1:707jCZHTUEnmiSYuDB0WyKhK9L0=
X-BSB-Auth: 1.0cc250d40400fdadcbd6.20211030011001BST.87sfwjtlt2.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 30 Oct 2021 00:10 UTC

Manfred <noname@add.invalid> writes:

> On 10/29/2021 6:30 PM, David Brown wrote:

>> In other words, it applies fine to the large majority of declarations.
>> You can add "inside out" to it to cover more cases.
>>
>> I understand that this is a simplification - but that's what people need
>> at the start.
>
> Not sure about that, at least not this kind of simplification.
> I think Bart made a good point, in noting that the right-to-left rule
> does not work well in some case, notably with pointers to arrays,
> which is something to be considered at any level of C knowledge.

The simple rule goes wrong for even simpler cases:

int a[3][5];
double f(double);

If you start at the name, the rule is to read to the right, and only
switch to reading left when you have to (which needs to be tied down).
This is because []s and ()s bind more tightly than *:

int *a[10];
>>>>> "a is an array of 10"
<<<<< "pointers to int"

The reference to "inside out" means you need to finish off parentheses
before moving outside:

int (*a)[10];
<< "a is a pointer to"
>>>>> "an array of 10"
<<<< "int"

Mind you, I don't usually do it this way. I read the declarator (the
part that decorates the name) like I do expressions. I don't vocalise

*a[10]

in an expression like

*a[10] = 42

I know the precedence and associativity so I know this is indexing 'a' and
dereferencing the result, as opposed to

(*a)[10] = 42

which dereferences a pointer and indexes the result.

--
Ben.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor