在下面的代码中,功能test和test2等效的是什么?
typedef int rofl;
void test(void) {
rofl * rofl = malloc(sizeof(rofl)); // Is the final rofl here the TYPE?
}
void test2(void) {
rofl * rofl = malloc(sizeof *rofl); // Is the final rofl here the VARIABLE?
}
Run Code Online (Sandbox Code Playgroud)
换一种说法:
rofl在sizeof(rofl)正确挑选rofl 类型,因为括号?rofl在sizeof *rofl正确地挑选rofl 可变的,因为一个缺少括号?注意:这是一个看起来很愚蠢的例子,但在实践中实际上你可以使用与变量名相同的类型名称.因此问题.