Re: A: a new bug to old plain C
Александр Поваляев via Gcc-h elp <[email protected]>
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <CAGT+J5wyPBrE8dbyAMa7i_8YqqrLRhjDrBZuE+=mP+R9zMas2Q@mail.gmail.com> |
Hi there! So, it looks like all the thread participants have read my
original request carefully (not only their own).
So, we have reached the First #1 milestone!
What we have learnt over a week:
1) First, two examples of why such conversion might be unsafe are
irrelevant.
Both examples, https://cigix.me/c23#6.5.17.2.p6 and the one posted by
Simon:
"void foo(int const *const p)
{
int *nonconst_p;
int *const *const pp = &nonconst_p;
*pp = p;
*nonconst_p = 42;
}" are NOT about "const Foo * const * const" types!
The first example is about possible unsafe conversion to " const char
**cpp;" type and the second "int *const *const".
But ONCE AGAIN, we are not considering either conversion to "const
char**cpp" or conversion to "int *const *const",
we ARE CONSIDERING CONVERSION TO "const Foo* const* const"!!! Please
take it into consideration.
NOTE: There was also one example (links) related to C++, BUT it is
also about not the same type conversion which the original my request was
about :(
2) Second, there is no explicit prohibition of such conversion ("Foo**" ->
"const Foo*const*const) in C standard.
3) Half of well-known compilers don't treat such conversion ("Foo**" ->
"const Foo*const*const) as an error. They might show a warning or doesn't
show it.
4) I showed a use-case where such conversion might be useful and why. I
think all the participants have read that post.
5) IF WE ARE TALKING ABOUT UNIFYING OF C STANDARD IMPLEMENTATION OVER ALL
THE COMPILERS AVAILABLE, WE CAN'T MAKE A PROHIBITION AS A GENERAL RULE,
SINCE
WE WILL FACE OUT BACK-COMPATIBILITY ISSUE WITH THE COMPILERS WHICH HAVE
ALREADY HAD SUPPORT OF SUCH CONVERSION.
Respectfully,
Aleksandr G Povaliaev.
ср, 26 нояб. 2025 г. в 21:39, Александр Поваляев <[email protected]>:
> Hi there!
>
> My reply gives a detailed description why the arguments you provided are
> not correct (as for the formal logic). Please try to be more accurate.
> We're talking about GCC (as I wrote in my original response to committee),
> not C++.
>
> And what I asked for is if С standard explicitly prohibits "Foo**" ->
> "const Foo * const * const" conversion.
> And I have not received any confirmation of it either from you or from the
> other participants of this e-mail thread.
>
> We're talking about the point which was implemented differently by
> compilers (see my previous post within the code snippet).
> And I am wondering why the things which are not explicitly prohibited by C
> standard are interpreted as errors, not warnings.
>
> As for now the bottom line: about 50% of well known C compilers don't
> interpret "Foo**" -> "const Foo * const * const" conversion as an error and
> there is no explicit prohibition of it by C standard.
> Right?
>
> As for "Foo**" -> "void*" -> "const Foo * const * const" conversion
> proposal. Yep it will work fine also, without error (see the results below).
> But once again, I would prefer not to deviate from the original topic.
> Thank you for your participation to this discussion.
>
> void subfunc(struct zzz const * const * const arg) {
>
> if (arg != NULL) {
> printf("%s", "Done!");
> }
> }
>
> void func(struct zzz ** arr_of_ptr, unsigned count) {
>
> subfunc((void*)arr_of_ptr); // CLANG: x86-64 clang (trunk) - OK!
> // GCC: x86-64 gcc (trunk) - OK!
> // INTEL: x86-64 icc 2021.10.0 - OK!
> // MICROSOFT(c++?): x64 msvc v19.latest - OK!
> // POWER64 GCC trunk - OK!
> // ARM gcc(trunk) - OK!
> // NOTE: based on godbolt.org
> }
>
> Respectfully,
> Aleksandr G Povaliaev.
>
> ср, 26 нояб. 2025 г. в 19:14, LIU Hao <[email protected]>:
>
>> 在 2025-11-26 21:48, Александр Поваляев 写道:
>> > I want to emphasize here "One of the following shall hold"!.
>> > So, if one of the following is being hold, the conversion/assignment is
>> permitted.
>>
>> > But USE THE SAME TRICK WITH DISJUNCTION AND CONJUNCTION to prove that
>> "Foo**" -> const Foo * const *
>> > const" is not correct.
>> > IT IS WRONG WAY.
>> > To be logically correct you need to show that NO ONE OF THE 6.5.17.2
>> STATEMENT is TRUE for "Foo**" ->
>> > const Foo * const * const" logic.
>>
>> If you had read the damn standard, you would have known that the others
>> are all about arithmetic types,
>> structs and unions, pointer to void, and conversion to `bool`, and
>> apparently they do not apply. Pity.
>>
>> Because you are writing C, you don't need to cast the pointer to `struct
>> zzz const * const * const`; you
>> just cast to `void*`. If you don't know that, you cannot know more C than
>> me.
>>
>> I'm already very disappointed about this thread, because half of the
>> messages are about `char **` does
>> not implicit convert to `const char **` which is technically a different
>> question from yours. And now I'm
>> getting more, because of your disrespect.
>>
>>
>> > But it is ok. It is usually being studied at some university courses,
>> so if you decide to enter some high
>> > education school you will learn all of these things.
>>
>> You are in no position to say that. We are well educated, and apparently
>> you are not such a person.
>>
>>
>> --
>> Best regards,
>> LIU Hao
>>
>