Hi,
Can someone confirm that *aObj->obj does NOT create any extray "code"
and does NOT do any
POINTER resolution? -> if so than "gcc" already uses the "friend" logic
I require :-)
→ I don't think that "gcc" do this already
On 03.02.20 09:12, Stefan Franke wrote:
On 03.02.20 08:37, Stefan Franke wrote:
....
The following solutions are acceptable:
1. "gcc" discover by its own that "base" is a "friend" of "A" and "B".
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
Simply use
method_base(&aObj.obj, ...)
method_base(&bObj.obj, ...)
cheers
Stefan
-----Ursprüngliche Nachricht-----
Von: aotto <aotto1968@xxxxxxxxxxx>
Gesendet: Montag, 3. Februar 2020 09:02
An: Stefan Franke <stefan@xxxxxxxxx>
Betreff: Re: AW: Feature request for "friendship" of pointers in "C"
This is not the same!
1. usually the aObj is a Pointer:
-> &aObj.obj => &(aObj->obj)
2. this DOUBLE indirect access creates definitely a CRASH if
aObj is invalid or freed
3. I use a internal a Pointer typecheck… where I can detect if
"my" pointer is valid or freed… but a "&(aObj->obj)" you
don't survive.
mfg
* Please reply at the bottom.
Ad 1: there is no need for '(' ')' if it's a pointer
&aObj->obj
Ad 2: this is not a double indirect access, the resulting address is the same as aObj as long obj is the first element of your struct, only the type changes
(void *)aObj == (void*)&aObj->obj
Ad 3: since the address is the same, your check will work.
Your issues aren't related to gcc - you might consider improving your C skills.
Cheers
Stefan