On 05/03/14 11:25 PM, comex wrote:
> On Wed, Mar 5, 2014 at 6:22 AM, Michael Neumann <mneum...@ntecs.de> wrote:
>> Try the same in C++:
>>
>>
>>     auto i = make_unique<int>(1234);
>>     auto j = std::move(i);
>>     cout << *j << endl; // 1234
>>     cout << *i << endl; // Segmentation Fault
> 
> Note that a move out of unique_ptr is guaranteed to leave the original
> null, so while this is not detected at compile time, it's also not
> memory-unsafe.

A null pointer dereference doesn't usually cause a segmentation fault in
kernel code. It causes one in userspace because the first page is
usually protected.

However, the C and C++ standards consider a null pointer dereference to
be undefined behaviour and GCC/LLVM encode this in their optimization
engines. It's in no way safe to dereference a null pointer with LLVM as
the compiler.

Type-checked moved semantics and type-checked reference lifetimes are in
my opinion the major safety improvements over C++. The other aspects of
a smart pointer type *can* be equally safe in both languages, but the
C++11 library smart pointers are not due to being nullable.

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to