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

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

 



On 2020-02-03 09:23 +0100, aotto wrote:
> Hi,
> 
> there is an easy test, if Stefan is right and I'm wrong.
> 
> 1. cast an INVALID Pointer to "aObj"
> 2. call "method_base(&aObj->obj,...)"
> 
> -> if stefan is right than "method_base" is called with an INVALID aObj 
> as Pointer
> -> if I am right than your software will CRASH :-)

If aObj is invalid, &aObj->obj would invoke undefined behavior.  We can't
predict what will happen so we shouldn't use &aObj->obj if aObj may be invalid.

> that is the reason why I require the "frienddef".

Then you should write to WG14 and try to convince them to add this to C2x.

Or, simply use a pointer cast.  If you think it looks ugly you can wrap it into
some macros.
-- 
Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[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