Initializing sigset_t in Rust

跟風遠走 提交于 2019-11-28 14:28:16

The standard library defines a couple of functions to deal with initialization. They are generic, so they can be used to initialize values of any type.

First, there's std::mem::uninitialized(), which gives you an uninitialized value. LLVM will consider the contents to be undefined, and will perform aggressive optimizations based on this. You must initialize any value before it's read.

Second, there's std::mem::zeroed(), which gives you a value whose storage is filled with zeroes. This function is unsafe because such a value is not necessarily legal for all types. zeroed() is appropriate for "plain old data" (POD) types.

How about using mem::zeroed? The docs (https://doc.rust-lang.org/std/mem/fn.zeroed.html) even say:

This is useful for FFI functions sometimes, but should generally be avoided.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!