Re: Feature request for "friendship" of pointers in "C"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 3 Feb 2020 at 07:21, aotto <aotto1968@xxxxxxxxxxx> wrote:
>
> 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"
>
> - a POINTER to "base" is NOT a valid POINTER to "A" and "B"
>
> I require a solution for this problem WITHOUT forced pointer cast
> code and without "void* and type-check" inflation.
>
> The following solutions are acceptable:
>
> 1. "gcc" discover by its own that "base" is a "friend" of "A" and "B".

I hate this idea, but I hate the use of the word "friend" even more.
Please pick a name that doesn't mean something different in C++
already.


> 2. add a "frienddef" keyword like "typedef" using:
>       typedef struct base * baseP;
>       typedef struct A    * aP;
>       typedef struct P    * bP;
>       frienddef baseP aP;
>       frienddef baseP bP;
> 3. add a #PRAGMA to enable/disable this feature
> 4. add a "gcc" api to easy extend "GCC" without being FORCED
>     to "hack" the core.
>
> thanks for your help
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux