[英]Why are stack values so far apart in Rust?
When I run当我跑
fn main() {
let x: i32 = 0;
println!("{:p}", &x);
let y: i32 = 1;
println!("{:p}", &y);
}
in the Rust playground , the values printed are, in decimal, 88 apart.在Rust 操场中,打印的值以十进制表示,相隔 88。 My expectation would be that they would be 4 or 8 (bytes) apart.
我的期望是它们相隔 4 或 8(字节)。 Why is it so large?
为什么这么大?
The println!
println!
macro will use stack variables too.宏也将使用堆栈变量。 If you swap the order of your statements around (in Rust Playground debug at least), the two pointers are 4 bytes apart:
如果您交换语句的顺序(至少在 Rust Playground 调试中),两个指针相隔 4 个字节:
fn main() {
let x: i32 = 0;
let y: i32 = 1;
println!("{:p}", &x); // 0x7ffe0b865db0
println!("{:p}", &y); // 0x7ffe0b865db4
}
There are no guarantees about how the stack is used, and it's very likely to be different with an optimised binary.无法保证堆栈的使用方式,并且很可能与优化的二进制文件不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.