- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
这段代码在 C++ 中是否有未定义的行为?
#include <cstdlib>
int main() {
int *ip = static_cast<int *>(std::malloc(sizeof *ip));
*ip = 42; //is this accessing an object that has not started its lifetime?
free(ip);
}
注意事项:
std::malloc
has the semantics that it has in C .在 C 中,std::malloc
创建有效的 int
,所以它应该是有效的?
The lifetime of an object or reference is a runtime property of the object or reference. An object is said to have non-vacuous initialization if it is of a class or aggregate type and it or one of its subobjects is initialized by a constructor other than a trivial default constructor. [ Note: Initialization by a trivial copy/move constructor is non-vacuous initialization. — end note ] The lifetime of an object of type T begins when:
(1.1) storage with the proper alignment and size for type T is obtained, and
(1.2) if the object has non-vacuous initialization, its initialization is complete,except that if the object is a union member or subobject thereof ...
我相当确定这句话回答了我的问题,但我对它的理解还不够好,无法判断它是说是还是不是。
我正在尝试在共享内存段中分配一个第三方类(不是我写的)。 不知道这个类是如何实现的,但它可能包含另一个"new"、“malloc”调用来为其需要分配内存。 这是否意味着这个新内存将不会在共享内存段内分
我是一名优秀的程序员,十分优秀!