Re: A: a new bug to old plain C
Александр Поваляев via Gcc-h elp <[email protected]>
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <CAGT+J5xPv5gxc_b78GQNtW+wOgUP3Lx-Z9yFoyC4MTdHUcxv_g@mail.gmail.com> |
Hi there! Either the links you've provided or the links you provided earlier (yesterday) are irrelevant, cause they are just discussing if it is safer to convert "Foo_Type **" to "const Foo_Type **" or not. Once again, we are not converting "char** to const char**", we're converting char** to const char * const * const". And we're not discussing if it is safer or not, we are discussing GCC compiler error. Respectfully, Aleksandr G Povaliaev. вс, 23 нояб. 2025 г. в 11:13, Jonathan Wakely <[email protected]>: > > > > On Sun, 23 Nov 2025, 03:19 Александр Поваляев, <[email protected]> > wrote: > >> Hi there! >> >> And again, we are not talking about warnings, some compilers show an >> error (so, it just stops compiling), some not. >> > > Yes, I understand that. GCC gives an error because the code violates the > rules of the C standard: > https://cigix.me/c23#6.5.17.2 > > There is an example in the C standard explicitly saying that the pointer > conversion from char** to const char** violates a constraint: > https://cigix.me/c23#6.5.17.2.p6 > > The C standard requires a diagnostic for a constraint violation: > https://cigix.me/c23#5.1.1.3.p1 > > >> I believe it should be fixed, because there is a quite evident use-case >> when using "const Foo * const * const" is in the order. >> >> And it is also quite in accordance with the recommendations given (links >> mentioned says "don't use const Foo **, cause it might be dangerous"). >> And what we're doing is not using "const Foo**". We tend to use "const >> Foo * const * const" instead. >> >> "const" is one of the cornerstones of C language, which prevents possible >> errors and makes programming safer. >> So, it should be handled appropriately. >> > > It is handled according to the C standard. > > I'm sorry you are unable to accept this, but I'm not going to waste any > more time replying in this thread. > > > > >> Respectfully, >> Aleksandr G Povaliaev. >> >> сб, 22 нояб. 2025 г. в 21:37, Jonathan Wakely <[email protected]>: >> >>> >>> >>> On Sat, 22 Nov 2025, 15:18 Александр Поваляев, <[email protected]> >>> wrote: >>> >>>> Hi there! >>>> >>>> The links you posted are all about "Don't use Foo** → const Foo**, use const >>>> Foo** to const Foo* const* conversion instead" >>>> (https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion, >>>> https://c-faq.com/ansi/constmismatch.html). >>>> Also, it is being discussed if it is safe or not to use such kind of >>>> conversion. >>>> >>>> But we don't use "Foo** -> const Foo**" conversion anyhow. >>>> We use "Foo** -> const Foo * const * const" conversion. So, we just >>>> follow the recommendation given and not the opposite. :) >>>> >>> >>> >>> And so your code would compile in C++. >>> >>> But like it says in the C FAQ, the rules for C and C++ are different. C >>> does not allow that conversion, even though it would be safe (and C++ does >>> allow it). >>> >>> Here is the relevant part: >>> >>> "C++ has more complicated rules for assigning const-qualified pointers >>> which let you make more kinds of assignments without incurring warnings, >>> but still protect against inadvertent attempts to modify const values. C++ >>> would still not allow assigning a char ** to a const char **, but it would >>> let you get away with assigning a char ** to a const char * const *.)" >>> >>> >>> >>> >>> >>>> Anyway some compilers return an error. And this is not the expected >>>> behaviour for use. It is A BUG!!! >>>> >>> >>> OK, maybe try a different compiler then. >>> >>> >>> >>> >>>> >>>>>> >>>>>>