Re: A: a new bug to old plain C
David Brown via Gcc-help <[email protected]>
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
On 21/11/2025 21:16, Jonathan Wakely via Gcc-help wrote: > On Fri, 21 Nov 2025, 17:48 Александр Поваляев via Gcc-help, < > [email protected]> wrote: > >> Hi there! >> >> Per my understanding it should work fine! Some compilers do work fine. Some >> compilers don't. So, this is "NON STABLE" behaviour. >> I am wondering why nobody else has reported this BUG before!!! >> > > It's not a bug. > To be more precise, it is not a bug in gcc. There may be other compilers that /do/ a related bug, in that they accept the incorrect code instead of rejecting it with an error. This can sometimes be a source of confusion - people think their code is valid because one compiler accepts it, and then think compilers that more accurately implement the C language are the ones with bugs. Aleksandr, please re-read through the posts in this thread, and in particular follow the links Jonathan gave to FAQs that discuss this issue. The question of how const and multiple pointer indirections interact is subtle and can easily be confusing. gcc is a big project, and there are bugs in it - but it is /extremely/ unlikely that it contains fundamental bugs in regard to the understanding of the C language standards. If there had been a bug in how it handles "const" and double pointers, it would have been noticed 35 years ago when gcc was young. You are not the first C programmer to mix "const" and multiple indirections - nor the first person to be in doubt about what is allowed and what is not allowed by the language. But you can be confident that gcc is correct here. If some other compiler accepts it, then that compiler is either intentionally lax, or unintentionally buggy. David > > >> The use-case is pretty simple: we are iterating over an array (I mean >> 'plain old C array). >> And so, we need a final point of iteration (end_ptr). >> >> In case of array ('plain old C array') of, let's say, integers, it would >> look like this: "const int * const end_of_iteration = array_ptr + count". >> And in case of array of pointers, it looks like: "const int * const * const >> end_of_iteration = array_ptr + count". >> >> Respectfully, >> Aleksandr G Povaliaev. >> >> >> пт, 21 нояб. 2025 г. в 06:24, Chris S <[email protected]>: >> >>> You're applying two consts to the same thing, so it's an error. >>> >>> "Const int" and "int const" are the same (look up East vs West const), >> but >>> "const int const" is an error. Declaring a pointer to that invalid type >>> declaration is still invalid. >>> >>> On Thu, Nov 20, 2025, 5:27 PM Александр Поваляев via Gcc-help < >>> [email protected]> wrote: >>> >>>> struct zzz { >>>> unsigned x, y; >>>> }; >>>> >>>> void square(struct zzz ** arr_of_ptr, unsigned count) { >>>> >>>> *// The first "const" produce an error (not a warning) within some GCC >>>> toolchains, for example ARM GCC trunk (linux), see goldbolt.org >>>> <http://goldbolt.org>* >>>> struct zzz const * const * const end_of_arr = arr_of_ptr + count; >>>> >>>> *// Without the first const "struct zzz * const * const end_of_arr = >>>> arr_of_ptr + count;" it works fine!!!* >>>> >>>> } >>>> >>>> Respectfully, >>>> Aleksandr G Povaliaev. >>>> >>> >> >