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 24/11/2025 11:07, Александр Поваляев via Gcc-help 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.
> 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.

Re-read the link to the C FAQ.  Read the C standard.  Or, at least, stop 
being so pig-headed and denying reality.

The links are not saying "don't do this because it is unsafe" - they say 
"the language does not allow this because it is unsafe".

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

The syntax is correct, but your conversion violates a constraint in the 
C language standards.  It is invalid code in C.

C++ allows a little more freedom in the conversions here than C does. 
"const" in C++ has many differences from "const" in C.  But you are 
talking about C code, not C++.  If you want to compiler your code as 
C++, go ahead - GCC will correctly apply the C++ rules and tell you 
whether the conversion is allowed or not.

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

And I need a coffee cup that refills itself every time I empty it.  I am 
more likely to get that wish fulfilled than you are to persuade the GCC 
developers to make their C compiler buggy in order to let you write a 
line of invalid C code.

Just fix your code.  Make the conversion explicit - put in a cast.  It 
is /really/ simple.  Maybe add a comment that you have no idea what you 
are doing, so people should not trust the code even though it compiles 
with the cast added.

There is no bug here in GCC - the flaw is entirely on /your/ side.
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.