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

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

 



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@xxxxxxxxxxx <mailto: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
    <mailto:aotto1968@xxxxxxxxxxx>> wrote:

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