&(void *){ NULL } 是什么意思

C语言 码拜 9年前 (2015-11-08) 1869次浏览
在研究 ffmpeg中遇到一个函数
void av_freep(void *arg)
{
void *val;
memcpy(&val, arg, sizeof(val));
memcpy(arg, &(void *){ NULL }, sizeof(val));   // 这个语句在gcc编译中能编译,而本人在VS中却无法编译提示错误
av_free(val);
}
// 然后本人用 memcpy(arg, NULL, sizeof(val)); 来代替, 结果gcc编译出来的ffmpeg库 却运行出错, 显然说明 不能这么替代,
问一下高手,  怎么样在VS中替代memcpy(arg, &(void *){ NULL }, sizeof(val));这句语句的实现
解决方案:50分
(void *){ NULL }
是 C99 的 compound literal
VS 不支持。
6.5.2.5 Compound literals
4 A postfix expression that consists of a parenthesized type name followed by a brace-enclosed list
of initializers is a compound literal. It provides an unnamed object whose
value is given by the initializer list.
&(void *){ NULL } 是取它的地址。
解决方案:25分
compound literals
C99的语法,注意msvc不支持C99,今后也很可能不会支持
解决方案:25分
void *pNULL = NULL;
memcpy(arg, &pNULL, sizeof(val));

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明&(void *){ NULL } 是什么意思
喜欢 (0)
[1034331897@qq.com]
分享 (0)