Re: A: a new bug to old plain C
LIU Hao via Gcc-help <[email protected]>
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
在 2025-11-26 18:12, Александр Поваляев 写道:
> [[[Aleksandr]]] So these types are not compatible. But the assignment goes without any error or warning.
Because you have asked someone to quote the standard, so you must think in the standard way.
Compatible types has nothing to do with any error or warnings. If two types are compatible, then they can
be re-interpreted as each other without conversion.
These two variables are also of incompatible types, but nevertheless, they can be assigned to each other:
int a = 1;
float b = 2;
a = b; // conversion happens
b = a; // conversion happens
> But the conversion is allowed by the second quoted paragraph. Although those pointers point to
> incompatible types, the conversion happens as a simple assignment, so qualified compatible types are
> also
> allowed. (The left operand can't have fewer qualifiers than the right operand.)
>
> [[[Aleksandr]]] What particular citation do you mean?
See this:
6.5.17 Assignment operators
6.5.17.2 Simple assignment
1 One of the following shall hold
— the left operand has atomic, qualified, or unqualified pointer type, and
(considering the type the left operand would have after lvalue conversion)
both operands are pointers to >>>>>>> qualified or unqualified versions of
compatible types <<<<<<<, and the type pointed to by the left operand has all
the qualifiers of the type pointed to by the right operand;
> [[[Aleksandr]]] Also. An important point to be mentioned: "Foo**"->"const Foo * const * const" conversion
> being compiled with "-Wno-incompatible-pointer-types" still produce an error :(
It's because they don't point to qualified compatible types. If you remove top-level * (to undo 'point
to'), then also remove top-level `const` (to undo 'qualified'), you get are `Foo *` and `const Foo *`,
and they are clearly not compatible.
--
Best regards,
LIU Hao
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEYmSQWY4DEzq4FUs4hfveZl3ogBsFAmkm1N0FAwAAAAAACgkQhfveZl3ogBtW /w/+K8a8mVLTY67cg0j6o+fZV1RRWVa+IOdrqM2gqTALlba3ujt42sU8vi7VX5oLhqBWsGf9w1Os gsJLIUshZPQO60bNLGlV/efjsSgzmANLdhsn2I/8c0t5tEtCz2NaUCSVe0WHp1fmOeHFxjtlj5kZ y5D6E3QbLS4lWmaO+XAU08OvuemuC5MTs6jAHNAriXEtDSNRLMliIy6FDHUgfcaBp84uVU8sZDNw k8oJXhXBeCprfqLHfNW0ke62wavKwoj3/XzyrcMHROzpdKG+K0ANbeSASNzFl+KF4FaJ+P4QaiPC +NfGuSw5zZqfPpHDUWeeOEaXkOYE/t+brUwa4EidOOZIQAMuM5c9EqUtqxT8+AsEMY0Bs+iWawp0 /8aCTKDHpma7RqjZSYcS51tpMRGPHuTpjl+kxiG65T4CJdX7IA7aPOlBkc2VYo0GSLJ5qlfxOgTo T/vp4jHgOWnLbjJW9WV7KU3lv35mfLflCMrWRx15Ac7TWaRDy6M2sjddZObIo3sPeZ/5DP3lArjl 9ZGxCoD12WznDaUzSYP3iwPpm0h6F3uMiDO3jw8+HH9T/EvR+w75F5GMi2aHiM15mvSlZb+6Z+Sd 7kSNyWc7eqgEWv4+adceienxEeS5bpUPmK+mIROrwcn579o2Z+j9xreLF5RAkBwWHPlOHcHdzX/a ODg= =q4fx -----END PGP SIGNATURE-----