Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #163259
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: on the order of the const-keyword |
| Date | 2021-10-30 01:10 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87sfwjtlt2.fsf@bsb.me.uk> (permalink) |
| References | (2 earlier) <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> |
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.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-28 12:50 -0300
Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-28 17:25 +0100
Re: on the order of the const-keyword "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-10-28 10:10 -0700
Re: on the order of the const-keyword Guillaume <message@bottle.org> - 2021-10-28 20:40 +0200
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 00:07 -0300
Re: on the order of the const-keyword James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-29 00:48 -0400
Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 12:56 -0700
Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 13:18 -0700
Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-28 21:35 +0100
Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 13:57 -0700
Re: on the order of the const-keyword Thiago Adams <thiago.adams@gmail.com> - 2021-10-28 14:07 -0700
Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-28 22:54 +0100
Re: on the order of the const-keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-28 15:37 -0700
Re: on the order of the const-keyword Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-29 00:02 +0100
Re: on the order of the const-keyword Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-28 22:10 +0100
Re: on the order of the const-keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-28 15:13 -0700
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 00:40 -0300
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-28 23:48 -0300
Re: on the order of the const-keyword James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-28 13:04 -0400
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 00:34 -0300
Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 10:03 +0200
Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-29 11:30 +0100
Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 16:31 +0200
Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-29 16:45 +0100
Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 18:30 +0200
Re: on the order of the const-keyword Manfred <noname@add.invalid> - 2021-10-30 00:32 +0200
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 20:03 -0300
Re: on the order of the const-keyword Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-30 01:10 +0100
Re: on the order of the const-keyword Bart <bc@freeuk.com> - 2021-10-29 23:51 +0100
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 12:22 -0300
Re: on the order of the const-keyword David Brown <david.brown@hesbynett.no> - 2021-10-29 18:34 +0200
Re: on the order of the const-keyword Meredith Montgomery <mmontgomery@levado.to> - 2021-10-29 17:04 -0300
csiph-web