Groups | Search | Server Info | Login | Register
Groups > comp.lang.c > #397445
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: pedantic gcc and const 2D arrays |
| Date | 2026-04-09 11:09 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <20260409110924.00000f9f@yahoo.com> (permalink) |
| References | <20260409012107.00006dc5@yahoo.com> <10r76oj$1vci$1@dont-email.me> |
On Wed, 8 Apr 2026 20:34:43 -0700 Andrey Tarasevich <noone@noone.net> wrote: > On Wed 4/8/2026 3:21 PM, Michael S wrote: > > > > What does it mean ? > > > > I already mentioned this issue here not so long ago. > > Again, an old puzzle about C const-correctness rules goes as follows: > > Is the following initialization > > T t; > const T *pt = &t; > > valid for all complete object types `T`? > > And the answer is "no". The above initialization is not valid if `T` > is an array type. E.g. given > > typedef int T[10]; > > the above initialization contains a constraint violation. Your > original example with 2D array is actually exactly the same thing, > once you take into account function argument type adjustment. > > This strange behavior is prescribed by > > 6.7.3 Type qualifiers > 9 If the specification of an array type includes any type > qualifiers, the element type is so qualified, not the array type. > > (quoted from C11) > > So, the fact that the `const` qualifier applied to array type "falls > through" to individual array elements is what prevents this > initialization from working. There's simply no provision in other > rules of the language (re: assignment constraints) that would permit > initialization of "pointer to an array of non-const elements" with a > "pointer to an array of const elements". > > C23 changed the above to the following: > > 6.7.4 Type qualifiers > 6.7.4.1 General > 10 If the specification of an array type includes any type > qualifiers, both the array and the element type are so-qualified. > > I.e. now const-qualification applies not only to the elements, but > also to the entire array type as well. With this change in place the > above initialization becomes valid. It now falls under the "usual" > const-correctness rules. In C23 arrays are no longer special in such > contexts. > Thank you.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
pedantic gcc and const 2D arrays Michael S <already5chosen@yahoo.com> - 2026-04-09 01:21 +0300
Re: pedantic gcc and const 2D arrays Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-08 15:57 -0700
Re: pedantic gcc and const 2D arrays Michael S <already5chosen@yahoo.com> - 2026-04-09 03:09 +0300
Re: pedantic gcc and const 2D arrays 🇵🇱Jacek Marcin Jaworski🇵🇱 <jmj@energokod.gda.pl> - 2026-04-09 02:33 +0200
Re: pedantic gcc and const 2D arrays Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-08 21:42 -0700
Re: pedantic gcc and const 2D arrays Andrey Tarasevich <noone@noone.net> - 2026-04-08 20:34 -0700
Re: pedantic gcc and const 2D arrays Michael S <already5chosen@yahoo.com> - 2026-04-09 11:09 +0300
Re: pedantic gcc and const 2D arrays "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-09 02:38 -0700
Re: pedantic gcc and const 2D arrays Michael S <already5chosen@yahoo.com> - 2026-04-09 14:06 +0300
Re: pedantic gcc and const 2D arrays "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-09 13:09 -0700
Re: pedantic gcc and const 2D arrays Andrey Tarasevich <noone@noone.net> - 2026-04-12 11:30 -0700
Re: pedantic gcc and const 2D arrays Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-13 05:40 -0700
csiph-web