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

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

 



On Mon, Feb 3, 2020 at 1:38 AM aotto <aotto1968@xxxxxxxxxxx> 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@xxxxxxxxxxx> wrote:
>
>> On 03.02.20 10:07, J Decker wrote:
>> > On Mon, Feb 3, 2020 at 12:23 AM aotto <aotto1968@xxxxxxxxxxx> 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)
>
>
>
>




[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