AW: AW: Feature request for "friendship" of pointers in "C"
aotto
aotto1968@t-online.de
Mon Feb 3 10:16:00 GMT 2020
Ok, it seems that I'was not convinced about the "safty" of "&aOut->out"
but it seems
that (at least gcc) add the aOut into the first item of "method_base".
-> This is infact the "frienddef" I required by "default" :-)
so - it seems it was my fould. and the tool https://godbolt.org/z/e_z8_y
include compile test
helped.
On 03.02.20 11:02, J Decker wrote:
>
>
> On Mon, Feb 3, 2020 at 1:38 AM aotto <aotto1968@t-online.de
> <mailto:aotto1968@t-online.de>> wrote:
>
> Hi, as i mentioned earlier⦠the "not having" create a couple of
> problems:
>
> 1. the "void-pointer-inflation"
> Â Â you can rewrite "method_base(struct base* hdl, ...)" win
> Â Â "method_base(void* hdl, ...)" this seems to solve the problem
> Â Â BUT you definitely loos the type-check because other pointer as
> "A" and "B"
> Â Â also allowed.
>
>
> 2. the "cast inflation"
> Â Â you can add the "CPP" wrapper to "method_base" this will act
> like "void*"
> Â Â but you loose the "type-check also"
>
>
> 3. even if you use "&aObj->obj" this create EXTRA CODE which add
> only CRASH-scenarios
>   and add EXTRA overheadâ¦
>
> 3. there is only ONE clear solution which NOT loose the
> "type-checking" and DON'T add
> Â Â extra code and this solution is the "frienddef"
>
>
> None of these are an issue, unless you're actually trying to go the
> other direction (getting an A* for B* from a base*), which none of
> your examples are exemplifiying....
> 1) nothing prevents you from passing the address of the base structure
> 2) I think you mean #define wrapper; which can still have your
> in-library type check for 'is a valid X'
> 3) does not create extra code, since your base pointer is the base of
> your structure, it'll still be NULL, unlike other places... you've
> already constrained it that it's the first member.
> 3(2)) since the rest of the points aren't themselves valid it doesn't
> appear there really needs to be an additional solution...
>
>
> mfg AO
>
> On 03.02.20 10:20, J Decker wrote:
>>
>>
>> On Mon, Feb 3, 2020 at 1:10 AM aotto <aotto1968@t-online.de
>> <mailto:aotto1968@t-online.de>> wrote:
>>
>> On 03.02.20 10:07, J Decker wrote:
>> > On Mon, Feb 3, 2020 at 12:23 AM aotto
>> <aotto1968@t-online.de <mailto:aotto1968@t-online.de>> wrote:
>> >
>> >> Hi,
>> >>
>> >> there is an easy test, if Stefan is right and I'm wrong.
>> >>
>> >> 1. cast an INVALID Pointer to "aObj"
>> >>
>> > how would friend prevent an invalid pointer pass?
>> â I have a pointer-type-and-valid test in my software, this mean
>> Â Â I know if a pointer is "valid" or not... but this works
>> only if
>> Â Â I get the pointer into my "base_method".
>>
>>
>> C doesn't have any such thing, no do any other developer, so how
>> would it help them? (you fell off the list)
>
More information about the Gcc-help
mailing list