小智 5
您可以将所需内容写入指向的内存位置void*,只要:
因此,做以下事情是合法的:
void* first = malloc(sizeof(void*));
*(void**)first = second;
....
void* another = *(void**)first; //Now another == second
Run Code Online (Sandbox Code Playgroud)
但其他任何事情,例如:
malloc(sizeof(int*)), 要么 malloc(4)void* first = &someCharArray[11] int* another = *(int**)first实施是否充分定义.有时未定义的行为.
这正是什么void*类型 - 你投了一些指针void*,然后你回头.您负责匹配的类型.
| 归档时间: |
|
| 查看次数: |
331 次 |
| 最近记录: |