Go来自C的一个比较值得注意的方面是,如果在其中声明了未使用的变量,编译器将不会构建您的程序.那么,如果在函数中声明了未使用的参数,那么为什么要构建这个程序呢?
func main() {
print(computron(3, -3));
}
func computron(param_a int, param_b int) int {
return 3 * param_a;
}
Run Code Online (Sandbox Code Playgroud) 我有这个结构类型,我malloc为,并在我释放后,指针仍然指向我分配的数据.这只是因为指针指向可以释放但尚未重新分配的内存吗?
#include <stdio.h>
typedef struct Katze {
int value;
} Katze;
int main () {
Katze *mew = malloc(sizeof(Katze));
mew->value = 8910;
free(mew);
printf("mew: %i\n", mew->value); // why does this still say "mew: 8910"?
}
Run Code Online (Sandbox Code Playgroud) 所以我有这个C程序示例.
int worship(long john)
{
return 0 * john;
}
int main()
{
return worship(666);
}
Run Code Online (Sandbox Code Playgroud)
该程序集(基本上)看起来像这样:
worship(long):
pushq %rbp
movq %rsp, %rbp
movq %rdi, -8(%rbp)
movl $0, %eax
popq %rbp
ret
main:
pushq %rbp
movq %rsp, %rbp
movl $666, %edi
call worship(long)
popq %rbp
ret
Run Code Online (Sandbox Code Playgroud)
我在阅读堆栈粉碎时遇到了这个问题.在汇编worship(long):部分,它表示movq %rdi, -8(%rbp)我希望它pushq基于我到目前为止阅读的所有内容.这是GCC将参数推送到堆栈的新方法吗?如果有的话,我可以使用编译器标志来切换它吗?
c ×2
compilation ×2
assembly ×1
gcc ×1
go ×1
parameters ×1
pointers ×1
stack ×1
struct ×1
variables ×1