Topic: Distinguish a pointer directly created by new
Author: wei zhang <lala.willzhang@gmail.com>
Date: Sun, 6 Aug 2017 21:37:02 -0700 (PDT)
Raw View
------=_Part_2805_230145680.1502080622031
Content-Type: multipart/alternative;
boundary="----=_Part_2806_1016315307.1502080622032"
------=_Part_2806_1016315307.1502080622032
Content-Type: text/plain; charset="UTF-8"
This actually is not a proposal, I don't even know how to implement it.
But we can discuss it.
I'm always thinking a pointer that directly created by new is different
from by other meanings.
A * ptr = new A();
Here we can ensure that this ptr is safer than which's retrieved by
following syntax,
A* ptr = &a;
or
A* ptr = &(ptrB->a); which *ptrB is the structure contains A a;
or
A* a = &a_vector[0]; here a_vector is vector<A>
The ptr directly created by new can be treated as an object's handler. And
in most cases this ptr will be valid until you call delete ptr manually or
by gc_count to 0 (in shared_ptr).
Actually in some cases, we should only accept that type of ptr. E.g. in
shared_ptr<A>( A* ptr); (this example even hope you write new A() inside
the parenthesis )
But the problem is how to track that information during runtime.
1. We might use a new keyword "safe" or "unsafe" when creating that ptr
(e.g. safe A * ptr = new A() ), but it requires all functions and structs
use the safe syntax to accept the safe ptr even for old libs, otherwise the
"safe" information will be lost after passing to the functions and
structures.
2. We could provide safe_cast<>() to convert an unknown safe ptr to safe
ptr with runtime check. So that for a ptr is safe or unsafe we need
runtime support.
3. We could provide static_safe_cast<>() for an unknown safe ptr to a safe
ptr, without runtime check.
4. How to treat A* ptr1 = new A() and A* ptr2 = new A[100]{} , do we treat
ptr2 as safe or not?
5. char * bytes = new char [sizeof(A)]; safe A * ptr = new (bytes) A{}
should be forbidden because replace new is unsafe, you will only get unsafe
A * ptr = new(bytes) A{}. I'm wondering we should make crash directly if
you do so. The only correct way is
void * bytes = malloc(sizeof(A) ); A* ptr = new (bytes) A{}
6. struct A{B firstVar;}; A * ptr = new A(); B * ptr2 =
reinterpret_cast<B*>(ptr); safe B* ptrB = dynamic_safe_cast<B*>(ptr2).
We should get null even if ptr2 is actual B * type.
7. in delete ptr; C runtime should check if the ptr is of safe type A.
(If with some compile flag)
I think it will be useful especially when someone want to provide a gc
manager in c++ language.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ae483b8-c7a6-4ed1-a2de-f68e4f2f4fc3%40isocpp.org.
------=_Part_2806_1016315307.1502080622032
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>This actually is not a proposal, I don't even kno=
w how to implement it. =C2=A0But we can discuss it.</div>I'm always thi=
nking a pointer that directly created by new is different from by other mea=
nings.<div>A * ptr =3D new A();</div><div>Here we can ensure that this ptr =
is safer than which's retrieved by following syntax,</div><div>A* ptr =
=3D &a;</div><div>or=C2=A0</div><div>A* ptr =3D =C2=A0&(ptrB->a)=
; which *ptrB is the structure contains A a;</div><div>or=C2=A0</div><div>A=
* a =3D &a_vector[0]; =C2=A0here a_vector is vector<A></div><div>=
<br></div><div>The ptr directly created by new can be treated as an object&=
#39;s handler. =C2=A0And in most cases this ptr will be valid until you cal=
l delete ptr manually or by gc_count to 0 (in shared_ptr).</div><div><br></=
div><div>Actually in some cases, we should only accept that type of ptr. =
=C2=A0E.g. in shared_ptr<A>( A* ptr); (this example even hope you wri=
te new A() inside the parenthesis )</div><div><br></div><div>But the proble=
m is how to track that information during runtime. =C2=A0</div><div>1. We m=
ight use a new keyword "safe" or "unsafe" when creating=
that ptr (e.g. safe A * ptr =3D new A() ), but it requires all functions a=
nd structs use the safe syntax to accept the safe ptr even for old libs, ot=
herwise the "safe" information will be lost after passing to the =
functions and structures.=C2=A0</div><div>2. We could provide safe_cast<=
>() to convert an unknown safe ptr to safe ptr with runtime check. =C2=
=A0So that for a ptr is safe or unsafe we need runtime support.<br></div><d=
iv>3. We could provide static_safe_cast<>() for an unknown safe ptr t=
o a safe ptr, without runtime check.</div><div>4. How to treat A* ptr1 =3D =
new A() and A* ptr2 =3D new A[100]{} , do we treat ptr2 as safe or not?</di=
v><div>5. char * bytes =3D new char [sizeof(A)]; =C2=A0safe A * ptr =3D new=
(bytes) A{} should be forbidden because replace new is unsafe, you will on=
ly get unsafe A * ptr =3D new(bytes) A{}. =C2=A0I'm wondering we should=
make crash directly if you do so. =C2=A0The only correct way is=C2=A0</div=
><div>void * bytes =3D malloc(sizeof(A) ); =C2=A0A* ptr =3D new (bytes) A{}=
</div><div>6. struct A{B firstVar;}; =C2=A0 =C2=A0A * ptr =3D new A(); =C2=
=A0B * ptr2 =3D reinterpret_cast<B*>(ptr); =C2=A0safe B* ptrB =3D dyn=
amic_safe_cast<B*>(ptr2). =C2=A0 We should get null even if ptr2 is a=
ctual B * type.</div><div>7. in delete ptr; =C2=A0C runtime should check if=
the ptr is of safe type A. =C2=A0(If with some compile flag)</div><div><br=
></div><div><br></div><div>I think it will be useful especially when someon=
e want to provide a gc manager in c++ language.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ae483b8-c7a6-4ed1-a2de-f68e4f2f4fc3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9ae483b8-c7a6-4ed1-a2de-f68e4f2f4fc3=
%40isocpp.org</a>.<br />
------=_Part_2806_1016315307.1502080622032--
------=_Part_2805_230145680.1502080622031--
.
Author: inkwizytoryankes@gmail.com
Date: Mon, 7 Aug 2017 10:53:30 -0700 (PDT)
Raw View
------=_Part_3424_323727300.1502128410098
Content-Type: multipart/alternative;
boundary="----=_Part_3425_1308487237.1502128410098"
------=_Part_3425_1308487237.1502128410098
Content-Type: text/plain; charset="UTF-8"
On Monday, August 7, 2017 at 6:37:02 AM UTC+2, wei zhang wrote:
>
> This actually is not a proposal, I don't even know how to implement it.
> But we can discuss it.
> I'm always thinking a pointer that directly created by new is different
> from by other meanings.
> A * ptr = new A();
> Here we can ensure that this ptr is safer than which's retrieved by
> following syntax,
> A* ptr = &a;
> or
> A* ptr = &(ptrB->a); which *ptrB is the structure contains A a;
> or
> A* a = &a_vector[0]; here a_vector is vector<A>
>
> The ptr directly created by new can be treated as an object's handler.
> And in most cases this ptr will be valid until you call delete ptr
> manually or by gc_count to 0 (in shared_ptr).
>
> Actually in some cases, we should only accept that type of ptr. E.g. in
> shared_ptr<A>( A* ptr); (this example even hope you write new A() inside
> the parenthesis )
>
> But the problem is how to track that information during runtime.
> 1. We might use a new keyword "safe" or "unsafe" when creating that ptr
> (e.g. safe A * ptr = new A() ), but it requires all functions and structs
> use the safe syntax to accept the safe ptr even for old libs, otherwise the
> "safe" information will be lost after passing to the functions and
> structures.
> 2. We could provide safe_cast<>() to convert an unknown safe ptr to safe
> ptr with runtime check. So that for a ptr is safe or unsafe we need
> runtime support.
> 3. We could provide static_safe_cast<>() for an unknown safe ptr to a safe
> ptr, without runtime check.
> 4. How to treat A* ptr1 = new A() and A* ptr2 = new A[100]{} , do we treat
> ptr2 as safe or not?
> 5. char * bytes = new char [sizeof(A)]; safe A * ptr = new (bytes) A{}
> should be forbidden because replace new is unsafe, you will only get unsafe
> A * ptr = new(bytes) A{}. I'm wondering we should make crash directly if
> you do so. The only correct way is
> void * bytes = malloc(sizeof(A) ); A* ptr = new (bytes) A{}
> 6. struct A{B firstVar;}; A * ptr = new A(); B * ptr2 =
> reinterpret_cast<B*>(ptr); safe B* ptrB = dynamic_safe_cast<B*>(ptr2).
> We should get null even if ptr2 is actual B * type.
> 7. in delete ptr; C runtime should check if the ptr is of safe type A.
> (If with some compile flag)
>
>
> I think it will be useful especially when someone want to provide a gc
> manager in c++ language.
>
Use separate type for that. Something in line of `std::shared_ptr` or
`std::unique_ptr`. You can define nearly all operation needed by you on
this new type.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/bc1a948d-f07a-4698-95cd-cf58975c21cc%40isocpp.org.
------=_Part_3425_1308487237.1502128410098
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, August 7, 2017 at 6:37:02 AM UTC+2, wei=
zhang wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
<div>This actually is not a proposal, I don't even know how to implemen=
t it. =C2=A0But we can discuss it.</div>I'm always thinking a pointer t=
hat directly created by new is different from by other meanings.<div>A * pt=
r =3D new A();</div><div>Here we can ensure that this ptr is safer than whi=
ch's retrieved by following syntax,</div><div>A* ptr =3D &a;</div><=
div>or=C2=A0</div><div>A* ptr =3D =C2=A0&(ptrB->a); which *ptrB is t=
he structure contains A a;</div><div>or=C2=A0</div><div>A* a =3D &a_vec=
tor[0]; =C2=A0here a_vector is vector<A></div><div><br></div><div>The=
ptr directly created by new can be treated as an object's handler. =C2=
=A0And in most cases this ptr will be valid until you call delete ptr manua=
lly or by gc_count to 0 (in shared_ptr).</div><div><br></div><div>Actually =
in some cases, we should only accept that type of ptr. =C2=A0E.g. in shared=
_ptr<A>( A* ptr); (this example even hope you write new A() inside th=
e parenthesis )</div><div><br></div><div>But the problem is how to track th=
at information during runtime. =C2=A0</div><div>1. We might use a new keywo=
rd "safe" or "unsafe" when creating that ptr (e.g. safe=
A * ptr =3D new A() ), but it requires all functions and structs use the s=
afe syntax to accept the safe ptr even for old libs, otherwise the "sa=
fe" information will be lost after passing to the functions and struct=
ures.=C2=A0</div><div>2. We could provide safe_cast<>() to convert an=
unknown safe ptr to safe ptr with runtime check. =C2=A0So that for a ptr i=
s safe or unsafe we need runtime support.<br></div><div>3. We could provide=
static_safe_cast<>() for an unknown safe ptr to a safe ptr, without =
runtime check.</div><div>4. How to treat A* ptr1 =3D new A() and A* ptr2 =
=3D new A[100]{} , do we treat ptr2 as safe or not?</div><div>5. char * byt=
es =3D new char [sizeof(A)]; =C2=A0safe A * ptr =3D new (bytes) A{} should =
be forbidden because replace new is unsafe, you will only get unsafe A * pt=
r =3D new(bytes) A{}. =C2=A0I'm wondering we should make crash directly=
if you do so. =C2=A0The only correct way is=C2=A0</div><div>void * bytes =
=3D malloc(sizeof(A) ); =C2=A0A* ptr =3D new (bytes) A{}</div><div>6. struc=
t A{B firstVar;}; =C2=A0 =C2=A0A * ptr =3D new A(); =C2=A0B * ptr2 =3D rein=
terpret_cast<B*>(ptr); =C2=A0safe B* ptrB =3D dynamic_safe_cast<B*=
>(ptr2). =C2=A0 We should get null even if ptr2 is actual B * type.</div=
><div>7. in delete ptr; =C2=A0C runtime should check if the ptr is of safe =
type A. =C2=A0(If with some compile flag)</div><div><br></div><div><br></di=
v><div>I think it will be useful especially when someone want to provide a =
gc manager in c++ language.</div></div></blockquote><div><br>Use separate t=
ype for that. Something in line of `std::shared_ptr` or `std::unique_ptr`. =
You can define nearly all operation needed by you on this new type.<br><br>=
</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/bc1a948d-f07a-4698-95cd-cf58975c21cc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bc1a948d-f07a-4698-95cd-cf58975c21cc=
%40isocpp.org</a>.<br />
------=_Part_3425_1308487237.1502128410098--
------=_Part_3424_323727300.1502128410098--
.
Author: wei zhang <lala.willzhang@gmail.com>
Date: Tue, 8 Aug 2017 00:42:36 -0700 (PDT)
Raw View
------=_Part_2451_1847884878.1502178156161
Content-Type: multipart/alternative;
boundary="----=_Part_2452_2114427826.1502178156161"
------=_Part_2452_2114427826.1502178156161
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
What if a lib that doesn't use directly_newed_ptr? How can I check the ptr=
=20
is directly newed if I get the ptr from a lib?
=E5=9C=A8 2017=E5=B9=B48=E6=9C=888=E6=97=A5=E6=98=9F=E6=9C=9F=E4=BA=8C UTC+=
8=E4=B8=8A=E5=8D=881:53:30=EF=BC=8CMarcin Jaczewski=E5=86=99=E9=81=93=EF=BC=
=9A
>
>
>
> On Monday, August 7, 2017 at 6:37:02 AM UTC+2, wei zhang wrote:
>>
>> This actually is not a proposal, I don't even know how to implement it.=
=20
>> But we can discuss it.
>> I'm always thinking a pointer that directly created by new is different=
=20
>> from by other meanings.
>> A * ptr =3D new A();
>> Here we can ensure that this ptr is safer than which's retrieved by=20
>> following syntax,
>> A* ptr =3D &a;
>> or=20
>> A* ptr =3D &(ptrB->a); which *ptrB is the structure contains A a;
>> or=20
>> A* a =3D &a_vector[0]; here a_vector is vector<A>
>>
>> The ptr directly created by new can be treated as an object's handler.=
=20
>> And in most cases this ptr will be valid until you call delete ptr=20
>> manually or by gc_count to 0 (in shared_ptr).
>>
>> Actually in some cases, we should only accept that type of ptr. E.g. in=
=20
>> shared_ptr<A>( A* ptr); (this example even hope you write new A() inside=
=20
>> the parenthesis )
>>
>> But the problem is how to track that information during runtime. =20
>> 1. We might use a new keyword "safe" or "unsafe" when creating that ptr=
=20
>> (e.g. safe A * ptr =3D new A() ), but it requires all functions and stru=
cts=20
>> use the safe syntax to accept the safe ptr even for old libs, otherwise =
the=20
>> "safe" information will be lost after passing to the functions and=20
>> structures.=20
>> 2. We could provide safe_cast<>() to convert an unknown safe ptr to safe=
=20
>> ptr with runtime check. So that for a ptr is safe or unsafe we need=20
>> runtime support.
>> 3. We could provide static_safe_cast<>() for an unknown safe ptr to a=20
>> safe ptr, without runtime check.
>> 4. How to treat A* ptr1 =3D new A() and A* ptr2 =3D new A[100]{} , do we=
=20
>> treat ptr2 as safe or not?
>> 5. char * bytes =3D new char [sizeof(A)]; safe A * ptr =3D new (bytes) =
A{}=20
>> should be forbidden because replace new is unsafe, you will only get uns=
afe=20
>> A * ptr =3D new(bytes) A{}. I'm wondering we should make crash directly=
if=20
>> you do so. The only correct way is=20
>> void * bytes =3D malloc(sizeof(A) ); A* ptr =3D new (bytes) A{}
>> 6. struct A{B firstVar;}; A * ptr =3D new A(); B * ptr2 =3D=20
>> reinterpret_cast<B*>(ptr); safe B* ptrB =3D dynamic_safe_cast<B*>(ptr2)=
.. =20
>> We should get null even if ptr2 is actual B * type.
>> 7. in delete ptr; C runtime should check if the ptr is of safe type A.=
=20
>> (If with some compile flag)
>>
>>
>> I think it will be useful especially when someone want to provide a gc=
=20
>> manager in c++ language.
>>
>
> Use separate type for that. Something in line of `std::shared_ptr` or=20
> `std::unique_ptr`. You can define nearly all operation needed by you on=
=20
> this new type.
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/fa633616-ff7a-44ad-80ac-880cf1d0051c%40isocpp.or=
g.
------=_Part_2452_2114427826.1502178156161
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">What if a lib that doesn't use directly_newed_ptr? =C2=
=A0How can I check the ptr is directly newed if I get the ptr from a lib?<d=
iv><br><br>=E5=9C=A8 2017=E5=B9=B48=E6=9C=888=E6=97=A5=E6=98=9F=E6=9C=9F=E4=
=BA=8C UTC+8=E4=B8=8A=E5=8D=881:53:30=EF=BC=8CMarcin Jaczewski=E5=86=99=E9=
=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
"><br><br>On Monday, August 7, 2017 at 6:37:02 AM UTC+2, wei zhang wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-=
left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>This actually i=
s not a proposal, I don't even know how to implement it. =C2=A0But we c=
an discuss it.</div>I'm always thinking a pointer that directly created=
by new is different from by other meanings.<div>A * ptr =3D new A();</div>=
<div>Here we can ensure that this ptr is safer than which's retrieved b=
y following syntax,</div><div>A* ptr =3D &a;</div><div>or=C2=A0</div><d=
iv>A* ptr =3D =C2=A0&(ptrB->a); which *ptrB is the structure contain=
s A a;</div><div>or=C2=A0</div><div>A* a =3D &a_vector[0]; =C2=A0here a=
_vector is vector<A></div><div><br></div><div>The ptr directly create=
d by new can be treated as an object's handler. =C2=A0And in most cases=
this ptr will be valid until you call delete ptr manually or by gc_count t=
o 0 (in shared_ptr).</div><div><br></div><div>Actually in some cases, we sh=
ould only accept that type of ptr. =C2=A0E.g. in shared_ptr<A>( A* pt=
r); (this example even hope you write new A() inside the parenthesis )</div=
><div><br></div><div>But the problem is how to track that information durin=
g runtime. =C2=A0</div><div>1. We might use a new keyword "safe" =
or "unsafe" when creating that ptr (e.g. safe A * ptr =3D new A()=
), but it requires all functions and structs use the safe syntax to accept=
the safe ptr even for old libs, otherwise the "safe" information=
will be lost after passing to the functions and structures.=C2=A0</div><di=
v>2. We could provide safe_cast<>() to convert an unknown safe ptr to=
safe ptr with runtime check. =C2=A0So that for a ptr is safe or unsafe we =
need runtime support.<br></div><div>3. We could provide static_safe_cast<=
;>() for an unknown safe ptr to a safe ptr, without runtime check.</div>=
<div>4. How to treat A* ptr1 =3D new A() and A* ptr2 =3D new A[100]{} , do =
we treat ptr2 as safe or not?</div><div>5. char * bytes =3D new char [sizeo=
f(A)]; =C2=A0safe A * ptr =3D new (bytes) A{} should be forbidden because r=
eplace new is unsafe, you will only get unsafe A * ptr =3D new(bytes) A{}. =
=C2=A0I'm wondering we should make crash directly if you do so. =C2=A0T=
he only correct way is=C2=A0</div><div>void * bytes =3D malloc(sizeof(A) );=
=C2=A0A* ptr =3D new (bytes) A{}</div><div>6. struct A{B firstVar;}; =C2=
=A0 =C2=A0A * ptr =3D new A(); =C2=A0B * ptr2 =3D reinterpret_cast<B*>=
;(ptr); =C2=A0safe B* ptrB =3D dynamic_safe_cast<B*>(ptr2). =C2=A0 We=
should get null even if ptr2 is actual B * type.</div><div>7. in delete pt=
r; =C2=A0C runtime should check if the ptr is of safe type A. =C2=A0(If wit=
h some compile flag)</div><div><br></div><div><br></div><div>I think it wil=
l be useful especially when someone want to provide a gc manager in c++ lan=
guage.</div></div></blockquote><div><br>Use separate type for that. Somethi=
ng in line of `std::shared_ptr` or `std::unique_ptr`. You can define nearly=
all operation needed by you on this new type.<br><br></div></div></blockqu=
ote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/fa633616-ff7a-44ad-80ac-880cf1d0051c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fa633616-ff7a-44ad-80ac-880cf1d0051c=
%40isocpp.org</a>.<br />
------=_Part_2452_2114427826.1502178156161--
------=_Part_2451_1847884878.1502178156161--
.
Author: "d25fe0be@outlook.com" <d25fe0be@outlook.com>
Date: Tue, 8 Aug 2017 11:35:45 +0000
Raw View
> On 8 Aug 2017, at 15:42, wei zhang <lala.willzhang@gmail.com> wrote:
>=20
> What if a lib that doesn't use directly_newed_ptr? How can I check the p=
tr is directly newed if I get the ptr from a lib?
>=20
You'll need a way to annotate pointers created by `new` anyway, whether usi=
ng a new type xxx_ptr (or existing `std::unique_ptr`), introducing a new ke=
ywords `safe`, or using even C++ attribute (as compilers are free to ignore=
unknown attributes, using attribute here may be a bad choice.).
Actually I do not see much difference between `safe T*` and `std::unique_pt=
r<T>`, given your use cases. (e.g. Use case `std::shared_ptr<T>(safe T*)` i=
s quite similar to `std::shared_ptr<T>(std::unique_ptr<T>)`).
OTOH, I'd like to suggest you to use `T*` only for non-owning pointers, and=
wrap all the owning pointers in some smart pointers. This way the concerns=
about where the pointer came from should be much less (or not at all).
> =E5=9C=A8 2017=E5=B9=B48=E6=9C=888=E6=97=A5=E6=98=9F=E6=9C=9F=E4=BA=8C UT=
C+8=E4=B8=8A=E5=8D=881:53:30=EF=BC=8CMarcin Jaczewski=E5=86=99=E9=81=93=EF=
=BC=9A
>=20
>=20
> On Monday, August 7, 2017 at 6:37:02 AM UTC+2, wei zhang wrote:
> This actually is not a proposal, I don't even know how to implement it. =
But we can discuss it.
> I'm always thinking a pointer that directly created by new is different f=
rom by other meanings.
> A * ptr =3D new A();
> Here we can ensure that this ptr is safer than which's retrieved by follo=
wing syntax,
> A* ptr =3D &a;
> or=20
> A* ptr =3D &(ptrB->a); which *ptrB is the structure contains A a;
> or=20
> A* a =3D &a_vector[0]; here a_vector is vector<A>
>=20
> The ptr directly created by new can be treated as an object's handler. A=
nd in most cases this ptr will be valid until you call delete ptr manually =
or by gc_count to 0 (in shared_ptr).
>=20
> Actually in some cases, we should only accept that type of ptr. E.g. in =
shared_ptr<A>( A* ptr); (this example even hope you write new A() inside th=
e parenthesis )
>=20
> But the problem is how to track that information during runtime. =20
Note that if runtime checks for `safe` are needed, ABI incompatibilities an=
d performance degradation are likely to be introduced.
> 1. We might use a new keyword "safe" or "unsafe" when creating that ptr (=
e.g. safe A * ptr =3D new A() ), but it requires all functions and structs =
use the safe syntax to accept the safe ptr even for old libs, otherwise the=
"safe" information will be lost after passing to the functions and structu=
res.=20
> 2. We could provide safe_cast<>() to convert an unknown safe ptr to safe =
ptr with runtime check. So that for a ptr is safe or unsafe we need runtim=
e support.
> 3. We could provide static_safe_cast<>() for an unknown safe ptr to a saf=
e ptr, without runtime check.
> 4. How to treat A* ptr1 =3D new A() and A* ptr2 =3D new A[100]{} , do we =
treat ptr2 as safe or not?
> 5. char * bytes =3D new char [sizeof(A)]; safe A * ptr =3D new (bytes) A=
{} should be forbidden because replace new is unsafe, you will only get uns=
afe A * ptr =3D new(bytes) A{}. I'm wondering we should make crash directl=
y if you do so. The only correct way is=20
> void * bytes =3D malloc(sizeof(A) ); A* ptr =3D new (bytes) A{}
> 6. struct A{B firstVar;}; A * ptr =3D new A(); B * ptr2 =3D reinterpr=
et_cast<B*>(ptr); safe B* ptrB =3D dynamic_safe_cast<B*>(ptr2). We shoul=
d get null even if ptr2 is actual B * type.
> 7. in delete ptr; C runtime should check if the ptr is of safe type A. =
(If with some compile flag)
>=20
>=20
> I think it will be useful especially when someone want to provide a gc ma=
nager in c++ language.
>=20
> Use separate type for that. Something in line of `std::shared_ptr` or `st=
d::unique_ptr`. You can define nearly all operation needed by you on this n=
ew type.
>=20
>=20
> --=20
> You received this message because you are subscribed to the Google Groups=
"ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/fa633616-ff7a-44ad-80ac-880cf1d0051c%40isocpp.=
org.
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/HK2PR03MB06755FF03828EB247AAA49B08B8A0%40HK2PR03=
MB0675.apcprd03.prod.outlook.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 8 Aug 2017 09:02:28 -0700 (PDT)
Raw View
------=_Part_4306_2025850924.1502208148472
Content-Type: multipart/alternative;
boundary="----=_Part_4307_2047413365.1502208148473"
------=_Part_4307_2047413365.1502208148473
Content-Type: text/plain; charset="UTF-8"
On Tuesday, August 8, 2017 at 3:42:36 AM UTC-4, wei zhang wrote:
>
> What if a lib that doesn't use directly_newed_ptr? How can I check the
> ptr is directly newed if I get the ptr from a lib?
>
If a library function returns a pointer that you have to delete, then that
library's documentation will tell you. Or it will use `gsl::owner<T*>` or
something similar. It's on the library to provide you the information you
need to effectively use its functions.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d059eafa-7970-4e0f-a5b9-7e0162aa5f83%40isocpp.org.
------=_Part_4307_2047413365.1502208148473
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, August 8, 2017 at 3:42:36 AM UTC-4, wei zhang =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">What if=
a lib that doesn't use directly_newed_ptr? =C2=A0How can I check the p=
tr is directly newed if I get the ptr from a lib?</div></blockquote><div><b=
r>If a library function returns a pointer that you have to delete, then tha=
t library's documentation will tell you. Or it will use `gsl::owner<=
T*>` or something similar. It's on the library to provide you the in=
formation you need to effectively use its functions.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d059eafa-7970-4e0f-a5b9-7e0162aa5f83%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d059eafa-7970-4e0f-a5b9-7e0162aa5f83=
%40isocpp.org</a>.<br />
------=_Part_4307_2047413365.1502208148473--
------=_Part_4306_2025850924.1502208148472--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 8 Aug 2017 16:38:15 -0700 (PDT)
Raw View
------=_Part_4942_909382632.1502235495161
Content-Type: multipart/alternative;
boundary="----=_Part_4943_1838848270.1502235495161"
------=_Part_4943_1838848270.1502235495161
Content-Type: text/plain; charset="UTF-8"
On Tuesday, August 8, 2017 at 12:42:36 AM UTC-7, wei zhang wrote:
>
> What if a lib that doesn't use directly_newed_ptr? How can I check the
> ptr is directly newed if I get the ptr from a lib?
>
To clarify and amplify what other people are telling you: You do *not* need
to know whether a pointer is "directly newed". That's not a thing. What you
need to know about a pointer is, "When I'm done using this pointer, should
I call delete on it? or delete[]? or free()? or something else? or
nothing?" And so what you are looking for is a way to attach that
"deleter" information to the pointer type, strongly and statically, and
even so that it happens automatically when you finish using the pointer.
This idea "strongly and statically, and even so that it happens
automatically when you finish using the pointer" is known in C++ as *RAII*.
The idea of using RAII on a pointer type is known in C++ as *smart pointers*
..
C++11 introduced two smart-pointer types, either one of which can be used
to solve your problem. std::unique_ptr<T, D> has a destructor that calls
D(T), and std::shared_ptr<T> has a destructor that calls some type-erased
function provided dynamically at constructor time.
If you have a function that returns the result of "new" (what we might call
an "indirectly newed pointer" :)), you should be wrapping the pointer in
unique_ptr the first chance you get. That is, instead of
X *foo() { return new X; }
you should be using
auto foo() { return std::unique_ptr<X>(new X); }
or, much much better,
auto foo() { return std::make_unique<X>(); }
This solves your problem because it attaches the data about "how do I free
this pointer" directly to the pointer object itself. You no longer have to
track that information manually.
HTH,
Arthur
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ebaa0279-90b0-4a66-ba87-bf806e2c982f%40isocpp.org.
------=_Part_4943_1838848270.1502235495161
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, August 8, 2017 at 12:42:36 AM UTC-7, wei zhang=
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">What i=
f a lib that doesn't use directly_newed_ptr? =C2=A0How can I check the =
ptr is directly newed if I get the ptr from a lib?</div></blockquote><div><=
br></div><div>To clarify and amplify what other people are telling you: You=
do <b><i>not</i></b> need to know whether a pointer is "directly newe=
d". That's not a thing. What you need to know about a pointer is, =
"When I'm done using this pointer, should I call <font face=3D"cou=
rier new, monospace">delete</font> on it? or <font face=3D"courier new, mon=
ospace">delete[]</font>? or <font face=3D"courier new, monospace">free()</f=
ont>? or something else? or nothing?" =C2=A0And so what you are lookin=
g for is a way to attach that "deleter" information to the pointe=
r type, strongly and statically, and even so that it happens automatically =
when you finish using the pointer.</div><div><br></div><div>This idea "=
;strongly and statically, and even so that it happens automatically when yo=
u finish using the pointer" is known in C++ as <b>RAII</b>.</div><div>=
<br></div><div>The idea of using RAII on a pointer type is known in C++ as =
<b>smart pointers</b>.</div><div><br></div><div>C++11 introduced two smart-=
pointer types, either one of which can be used to solve your problem. std::=
unique_ptr<T, D> has a destructor that calls D(T), and std::shared_pt=
r<T> has a destructor that calls some type-erased function provided d=
ynamically at constructor time.</div><div><br></div><div>If you have a func=
tion that returns the result of "new" (what we might call an &quo=
t;indirectly newed pointer" :)), you should be wrapping the pointer in=
unique_ptr the first chance you get. That is, instead of</div><div><br></d=
iv><div>=C2=A0 =C2=A0 X *foo() { return new X; }</div><div><br></div><div>y=
ou should be using</div><div><br></div><div>=C2=A0 =C2=A0 auto foo() { retu=
rn std::unique_ptr<X>(new X); }</div><div><br></div><div>or, much muc=
h better,</div><div><br></div><div>=C2=A0 =C2=A0 auto foo() { return std::m=
ake_unique<X>(); }</div><div><br></div><div>This solves your problem =
because it attaches the data about "how do I free this pointer" d=
irectly to the pointer object itself. You no longer have to track that info=
rmation manually.</div><div><br></div><div>HTH,</div><div>Arthur</div></div=
>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ebaa0279-90b0-4a66-ba87-bf806e2c982f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ebaa0279-90b0-4a66-ba87-bf806e2c982f=
%40isocpp.org</a>.<br />
------=_Part_4943_1838848270.1502235495161--
------=_Part_4942_909382632.1502235495161--
.
Author: Will Zhang <lala.willzhang@gmail.com>
Date: Thu, 10 Aug 2017 19:16:10 +0800
Raw View
--001a113d830aed1473055664525d
Content-Type: text/plain; charset="UTF-8"
The problem is that it doesn't everywhere use std::xxxx_ptr. And I don't
think for a C++ programing it should use std::xxxx_ptr everywhere.
The philosophy is in current c/c++, a pointer is just a memory address.
Now I hope at least we are able to know if a pointer is just an address or
it's an object, by c++ language itself.
Someone may ask is c++ an object oriented language? Most of us will say
yes, "but we don't know if a pointer is an object or just an address"
someone will added.
Thanks
Will Zhang
Will Zhang
2017-08-09 7:38 GMT+08:00 Arthur O'Dwyer <arthur.j.odwyer@gmail.com>:
> On Tuesday, August 8, 2017 at 12:42:36 AM UTC-7, wei zhang wrote:
>>
>> What if a lib that doesn't use directly_newed_ptr? How can I check the
>> ptr is directly newed if I get the ptr from a lib?
>>
>
> To clarify and amplify what other people are telling you: You do *not*
> need to know whether a pointer is "directly newed". That's not a thing.
> What you need to know about a pointer is, "When I'm done using this
> pointer, should I call delete on it? or delete[]? or free()? or something
> else? or nothing?" And so what you are looking for is a way to attach that
> "deleter" information to the pointer type, strongly and statically, and
> even so that it happens automatically when you finish using the pointer.
>
> This idea "strongly and statically, and even so that it happens
> automatically when you finish using the pointer" is known in C++ as *RAII*
> .
>
> The idea of using RAII on a pointer type is known in C++ as *smart
> pointers*.
>
> C++11 introduced two smart-pointer types, either one of which can be used
> to solve your problem. std::unique_ptr<T, D> has a destructor that calls
> D(T), and std::shared_ptr<T> has a destructor that calls some type-erased
> function provided dynamically at constructor time.
>
> If you have a function that returns the result of "new" (what we might
> call an "indirectly newed pointer" :)), you should be wrapping the pointer
> in unique_ptr the first chance you get. That is, instead of
>
> X *foo() { return new X; }
>
> you should be using
>
> auto foo() { return std::unique_ptr<X>(new X); }
>
> or, much much better,
>
> auto foo() { return std::make_unique<X>(); }
>
> This solves your problem because it attaches the data about "how do I free
> this pointer" directly to the pointer object itself. You no longer have to
> track that information manually.
>
> HTH,
> Arthur
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/ebaa0279-90b0-4a66-
> ba87-bf806e2c982f%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ebaa0279-90b0-4a66-ba87-bf806e2c982f%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADwui2T%3D2m5ojsUtoAP8-wWpuY%2BCkd4WSKZCVCWGXqPGtwiiJA%40mail.gmail.com.
--001a113d830aed1473055664525d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The problem is that it doesn't everywhere use=C2=A0<sp=
an style=3D"font-size:14px">=C2=A0std::xxxx_ptr.=C2=A0 And I don't thin=
k for a C++ programing it should use std::xxxx_ptr everywhere. =C2=A0</span=
><div><br></div><div><span style=3D"font-size:14px"><br></span><div>The phi=
losophy is in current c/c++, a pointer is just a memory address.=C2=A0 Now =
I hope at least we are able to know if a pointer is just an address or it&#=
39;s an object, by c++ language itself.</div></div><div><br></div><div>Some=
one may ask is c++ an object oriented language?=C2=A0 Most of us will say y=
es, "but we don't know if a pointer is an object or just an addres=
s" someone will added.</div><div><br></div><div>Thanks</div><div>Will =
Zhang</div><div><br></div></div><div class=3D"gmail_extra"><br clear=3D"all=
"><div><div class=3D"gmail_signature" data-smartmail=3D"gmail_signature">Wi=
ll Zhang</div></div>
<br><div class=3D"gmail_quote">2017-08-09 7:38 GMT+08:00 Arthur O'Dwyer=
<span dir=3D"ltr"><<a href=3D"mailto:arthur.j.odwyer@gmail.com" target=
=3D"_blank">arthur.j.odwyer@gmail.com</a>></span>:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr"><span class=3D"">On Tuesday, August 8, 2017 =
at 12:42:36 AM UTC-7, wei zhang wrote:<blockquote class=3D"gmail_quote" sty=
le=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr">What if a lib that doesn't use directly_newed_ptr?=
=C2=A0 How can I check the ptr is directly newed if I get the ptr from a li=
b?</div></blockquote><div><br></div></span><div>To clarify and amplify what=
other people are telling you: You do <b><i>not</i></b> need to know whethe=
r a pointer is "directly newed". That's not a thing. What you=
need to know about a pointer is, "When I'm done using this pointe=
r, should I call <font face=3D"courier new, monospace">delete</font> on it?=
or <font face=3D"courier new, monospace">delete[]</font>? or <font face=3D=
"courier new, monospace">free()</font>? or something else? or nothing?"=
; =C2=A0And so what you are looking for is a way to attach that "delet=
er" information to the pointer type, strongly and statically, and even=
so that it happens automatically when you finish using the pointer.</div><=
div><br></div><div>This idea "strongly and statically, and even so tha=
t it happens automatically when you finish using the pointer" is known=
in C++ as <b>RAII</b>.</div><div><br></div><div>The idea of using RAII on =
a pointer type is known in C++ as <b>smart pointers</b>.</div><div><br></di=
v><div>C++11 introduced two smart-pointer types, either one of which can be=
used to solve your problem. std::unique_ptr<T, D> has a destructor t=
hat calls D(T), and std::shared_ptr<T> has a destructor that calls so=
me type-erased function provided dynamically at constructor time.</div><div=
><br></div><div>If you have a function that returns the result of "new=
" (what we might call an "indirectly newed pointer" :)), you=
should be wrapping the pointer in unique_ptr the first chance you get. Tha=
t is, instead of</div><div><br></div><div>=C2=A0 =C2=A0 X *foo() { return n=
ew X; }</div><div><br></div><div>you should be using</div><div><br></div><d=
iv>=C2=A0 =C2=A0 auto foo() { return std::unique_ptr<X>(new X); }</di=
v><div><br></div><div>or, much much better,</div><div><br></div><div>=C2=A0=
=C2=A0 auto foo() { return std::make_unique<X>(); }</div><div><br></=
div><div>This solves your problem because it attaches the data about "=
how do I free this pointer" directly to the pointer object itself. You=
no longer have to track that information manually.</div><div><br></div><di=
v>HTH,</div><div>Arthur</div></div><span class=3D"">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ebaa0279-90b0-4a66-ba87-bf806e2c982f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/ebaa=
0279-90b0-4a66-<wbr>ba87-bf806e2c982f%40isocpp.org</a><wbr>.<br>
</blockquote></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CADwui2T%3D2m5ojsUtoAP8-wWpuY%2BCkd4W=
SKZCVCWGXqPGtwiiJA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADwui2T%3D2m=
5ojsUtoAP8-wWpuY%2BCkd4WSKZCVCWGXqPGtwiiJA%40mail.gmail.com</a>.<br />
--001a113d830aed1473055664525d--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 10 Aug 2017 07:21:49 -0700 (PDT)
Raw View
------=_Part_908_812075949.1502374909422
Content-Type: multipart/alternative;
boundary="----=_Part_909_655488530.1502374909422"
------=_Part_909_655488530.1502374909422
Content-Type: text/plain; charset="UTF-8"
On Thursday, August 10, 2017 at 7:16:14 AM UTC-4, wei zhang wrote:
>
> The problem is that it doesn't everywhere use std::xxxx_ptr. And I
> don't think for a C++ programing it should use std::xxxx_ptr everywhere.
>
.... why not? It solves your problem, doesn't it?
The philosophy is in current c/c++, a pointer is just a memory address.
> Now I hope at least we are able to know if a pointer is just an address or
> it's an object, by c++ language itself.
>
Well, that's not gonna happen. We're not going to create yet another
language-created construct like `T*` for something this trivial. Since 100%
of code today uses pointers rather than this new `T~`, that means nobody's
code will be in any way improved without them doing manual work.
And if they have to change from `T*` to `T~`, they could just as easily
change from `T*` to `owner<T*>`.
Someone may ask is c++ an object oriented language? Most of us will say
> yes, "but we don't know if a pointer is an object or just an address"
> someone will added.
>
"Most of us" will most certainly *not* say "yes". And quite frankly, the
first bit of non-OOP most of us will think of is not the fact that a
pointer doesn't have to be a valid pointer.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/da212904-631b-4f2b-bb52-87e5bd77de22%40isocpp.org.
------=_Part_909_655488530.1502374909422
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, August 10, 2017 at 7:16:14 AM UTC-4, wei zhan=
g wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">The p=
roblem is that it doesn't everywhere use=C2=A0<span style=3D"font-size:=
14px">=C2=A0std::xxxx_ptr.=C2=A0 And I don't think for a C++ programing=
it should use std::xxxx_ptr everywhere.<br></span></div></blockquote><div>=
<br>... why not? It solves your problem, doesn't it?<br><br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><span style=3D"fon=
t-size:14px"></span><div><span style=3D"font-size:14px"></span><div>The phi=
losophy is in current c/c++, a pointer is just a memory address.=C2=A0 Now =
I hope at least we are able to know if a pointer is just an address or it&#=
39;s an object, by c++ language itself.</div></div></div></blockquote><div>=
<br>Well, that's not gonna happen. We're not going to create yet an=
other language-created construct like `T*` for something this trivial. Sinc=
e 100% of code today uses pointers rather than this new `T~`, that means no=
body's code will be in any way improved without them doing manual work.=
<br><br>And if they have to change from `T*` to `T~`, they could just as ea=
sily change from `T*` to `owner<T*>`.<br><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><div>Someone may as=
k is c++ an object oriented language?=C2=A0 Most of us will say yes, "=
but we don't know if a pointer is an object or just an address" so=
meone will added.</div></div></blockquote><div><br>"Most of us" w=
ill most certainly <i>not</i> say "yes". And quite frankly, the f=
irst bit of non-OOP most of us will think of is not the fact that a pointer=
doesn't have to be a valid pointer.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/da212904-631b-4f2b-bb52-87e5bd77de22%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/da212904-631b-4f2b-bb52-87e5bd77de22=
%40isocpp.org</a>.<br />
------=_Part_909_655488530.1502374909422--
------=_Part_908_812075949.1502374909422--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Thu, 10 Aug 2017 08:51:52 -0700
Raw View
On quinta-feira, 10 de agosto de 2017 04:16:10 PDT Will Zhang wrote:
> The philosophy is in current c/c++, a pointer is just a memory address.
> Now I hope at least we are able to know if a pointer is just an address or
> it's an object, by c++ language itself.
Even assuming the rest of your arguments were valid, which I don't think they
are, this bit here is not what you want to know. First of all, what would a
pointer be pointing to if not to an object?
More importantly, pointing to a sub-object of a larger object is still
pointing to an object. But that isn't compatible with everything else you
said.
No, I agree with Arthur: you don't want to know what the pointer points to.
You want to know what to do with the pointer once you no longer need it.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1630545.la1fJYtAlR%40tjmaciei-mobl1.
.