Re: A: a new bug to old plain C

Jonathan Wakely via Gcc-help <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <CAH6eHdTB2zZSRnELSXPSsV2P+eTFvZN-=cHNjavZC8iiJ=9_qg@mail.gmail.com>
On Mon, 24 Nov 2025 at 10:07, Александр Поваляев <[email protected]> wrote:
>
> Hi there!
>
> The code is not invalid and neither of the links posted saying that "const Foo * const * const" is invalid construction for C.

Have you bumped your head? Do you have trouble reading?

The C FAQ very clearly says that C++ allows that conversion but C
doesn't. If C allowed it, why would it say that C++ is different? Does
that make sense?

Yes, I know it says "warnings" but it's talking about diagnostics
emitted for invalid code. For GCC, those diagnostics are now errors,
since GCC 14. GCC now gives errors not warnings because the code is
invalid in C. It's valid in C++. What part of that do you not
understand?


> The links posted just are discussing that it might be UNSAFE to cast "Foo **" -> "const Foo **" and recommending usage of "Foo **" -> "const Foo * const *" instead.
> It's OK. If you feel that it is unsafe, please don't use it. It is your own decision.

The C standard says it's invalid. The *reason* is because some
conversions are unsafe, so they are not allowed in C. But it's a fact
that they're not allowed in C.

If you want to do the conversion anyway, use an explicit cast:

struct zzz const * const * const end_of_arr = (struct zzz
const**)arr_of_ptr + count;

Or disable the diagnostics with  -Wno-incompatible-pointer-types

>
> But the syntax itself "const Foo * const * const" is correct and the use-case I mentioned is quite simple and evident.

No, the syntax is not correct. You can keep insisting it is correct,
but it's not valid in the C language (only in C++).

Continuing to insist that it's valid just makes you look stupid. Maybe
you can get an LLM to explain it to you in words that you understand?

> And so I need this code snipped to be compiled transparently over all the GCC (and platform SDKs) available versions.

Use an explicit cast or use  -Wno-incompatible-pointer-types to
disable the diagnostics.

https://gcc.gnu.org/gcc-14/porting_to.html#incompatible-pointer-types
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.