Re: A: a new bug to old plain C
Александр Поваляев via Gcc-h elp <[email protected]>
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <CAGT+J5waCqb7QFgShrvs4zdhFAwma5TE3FLTnhVEqNbJ6B--cQ@mail.gmail.com> |
Hi there! And again, we are not talking about warnings, some compilers show an error (so, it just stops compiling), some not. 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. 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. > > > > >> >>>> >>>>