Re: A: a new bug to old plain C

Александр Поваляев via Gcc-h elp <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <CAGT+J5y_=ay4WJu-MHtWxCP-fCB3kdY3XoomGrwy06b2=m4TeQ@mail.gmail.com>
Your mentioned the following text snippet from C standard:
"
6.7.4 Type qualifiers
    6.7.4.1 General

    11 For two qualified types to be compatible, both shall have >>>>>>> the
       identically qualified version <<<<<<< of a compatible type; the
order of
       type qualifiers within a list of specifiers or qualifiers does not
affect the
       specified type.
".

So, the last code sample does a conversion between "non compatible" types
without any error or warning.


ср, 26 нояб. 2025 г. в 12:48, LIU Hao <[email protected]>:

> 在 2025-11-26 17:37, Александр Поваляев 写道:
> > Hi there!
> >
> > The code below works fine on all the GCC compilers. It doesn't provide
> either errors or warnings.
> >
> > "
> > struct zzz {
> > unsigned x, y;
> > };
> >
> >
> > void square(struct zzz * arr_of_ptr, unsigned count) {
> >
> > struct zzz * const ptr1 = arr_of_ptr; // OK!
> > struct zzz const * ptr2 = arr_of_ptr; // OK!
> > struct zzz const * const ptr3 = arr_of_ptr; // OK!
> >
> > }
> > "
>
> These are not the same as your original code. These are pointers to
> 'qualified or unqualified versions of
> compatible type(s)', where the 'compatible type' is `struct zzz *`.
>
> In your original code there's `struct zzz ** arr_of_ptr` which points to
> `struct zzz *`, and there's
> `struct zzz const * const * const end_of_arr` which points to
> const-qualified `struct zzz const *`, so
> those pointers point to incompatible different types, and are not
> convertible.
>
>
>
> --
> Best regards,
> LIU Hao
>
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.