Closed
Description
Perhaps we should add an intrinsic like:
fn zero<T: POD>() -> T
that basically fills T
with zeros. This is perfectly safe for POD types. Of course, we don't have a POD kind yet, but that's a separate issue I guess. This is particularly useful in C interop, where you often have functions with out-params that otherwise need to be initialized by hand.
We could also add an intrinsic like
fn undefined<T: POD>() -> T
which would just leave the data uninitialized. This would be more efficient but less safe in some sense. Though restricting it to POD at least preserves memory safety, more-or-less.
The idea is you'd write something like:
struct FooResult { /*something POD*/ }
extern mod c_library { fn foo(p: &mut FooResult) -> bool; }
fn foo() -> FooResult {
let result = defined();
if !c_library::foo(&mut result) { fail; }
return result;
}
Metadata
Metadata
Assignees
Labels
No labels