Feature request for "friendship" of pointers in "C"
Florian Weimer
fw@deneb.enyo.de
Wed Mar 18 08:23:27 GMT 2020
* aotto:
> Hi, the following scenario has a "definition hole" in the "C" language
>
> code example:
>
> -------------------------
> struct base {
> ...
> };
>
> struct A {
> struct base obj;
> ...
> } aObj;
>
> struct B {
> struct base obj;
> ...
> } bObj;
>
> void method_base (struct base * hdl, ...);
>
> method_base(&aObj, ...)
> method_base(&bObj, ...)
> ------------------------
>
> - a POINTER to "A" is also a valid POINTER to "base"
>
> - a POINTER to "B" is also a valid POINTER to "base"
This is close to one of the extensions enabled by -fplan9-extensions.
It accepts such code if you make the base member anonymous:
struct A {
struct base;
...
} aObj;
struct B {
struct base;
...
} bObj;
More information about the Gcc
mailing list