I'm learning about memory alignments, and I found the difference about arguments.
With Windows 11 64bits, long long
as the pointer size.
rs
With rustc 1.75.0-nightly (d627cf07c 2023-10-10)
:
extern "cdecl" fn a(a:usize,b:u8,c:u8) {
println!("a:{:p} b:{:p} c:{:p}",&a,&b,&c);
unsafe{println!("{:x?}",std::slice::from_raw_parts(&a as *const usize as *const u8, 24))}
};
a(0x123f,0x55,0x23);
a:0xf1401ff260 b:0xf1401ff26e c:0xf1401ff26f
[3f, 12, 0, 0, 0, 0, 0, 0,
0, 15, ef, 2c, b5, 1, 55, 23,
28, c4, be, 7, f7, 7f, 0, 0]
So both u8 arguments are together at end of the second pointer area.
C
With MSVC cl.exe 19.36.32532 and linker.exe 14.36.32532.0
void __cdecl t(long long a,char b, char c) {
printf("%X %X %X \n",&a,&b,&c);
char* bytes = (char*)(&a);
for (char i = 0; i < 24; i++) {
printf("%X ",bytes[i]);
};
}
int main() {
t(0x123f,0x55,0x23);
};
3F 12 0 0 0 0 0 0
55 0 0 0 0 0 0 0
23 0 0 0 0 0 0 0
Is this the expect result?