在AMD64上简单分配两个缓冲区 [英] Simple allocation of two buffer on AMD64

查看:73
本文介绍了在AMD64上简单分配两个缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 由GCC编制的代码:


int main(无效)

{

char a [] =" 123" ;;

char b [] =" abc";


printf("%p%p \ n",a,b) ;


返回0;

}


- 在AMD64上运行它给了我:


0x7fff929c9410 0x7fff929c9400

- 两个地址和

之间的16字节距离不仅仅是8个字节的原因是什么?

解决方案

ji *** ******@gmail.com 写道:


- GCC编译的代码:


int main(void)

{

char a [] =" 123";

char b [] =" abc" ;;


printf("%p%p \ n",a,b);


返回0;

}


- 在AMD64上运行它给了我:


0x 7fff929c9410 0x7fff929c9400

- 两个地址和

之间的16字节距离不仅仅是8个字节的原因是什么?



询问gcc实现者。是他们决定编译器应该如何分配空间,而不是C语言本身。

C不需要16字节分隔,但不是

禁止它。


-

Eric Sosman
es ***** @ ieee-dot-org.inva lid


ji ********* @ gmail.com 写道:


- 由GCC编写的代码:


int main(无效)

{

char a [] =" 123" ;;

char b [] =" abc";


printf("%p%p \ n",a,b);



将'a''和'b''置为无效*。


>

返回0;

}


- 在AMD64上运行它给了我:


0x7fff929c9410 0x7fff929c9400

- 两个地址和

之间的16字节距离不仅仅是8个字节的原因是什么?



这是标准C未提及的实现细节。由于对齐原因,它可能是b $ b。


这是标准C没有提及的实现细节。可能


由于对齐原因。



我知道。只是对8字节16字节的选择的好奇心(我希望b $ b预计)。


无论如何,谢谢。


- Code compiled by GCC:

int main(void)
{
char a[] = "123";
char b[] = "abc";

printf("%p %p\n", a, b);

return 0;
}

- Running it on AMD64 gives me:

0x7fff929c9410 0x7fff929c9400

- What is the reason for 16 bytes of distance between two address and
not just 8 bytes?

解决方案

ji*********@gmail.com wrote:

- Code compiled by GCC:

int main(void)
{
char a[] = "123";
char b[] = "abc";

printf("%p %p\n", a, b);

return 0;
}

- Running it on AMD64 gives me:

0x7fff929c9410 0x7fff929c9400

- What is the reason for 16 bytes of distance between two address and
not just 8 bytes?

Ask the gcc implementors. It was they who decided how
the compiler should allocate space, not the C language itself.
C does not require a sixteen-byte separation, but does not
forbid it.

--
Eric Sosman
es*****@ieee-dot-org.invalid


ji*********@gmail.com wrote:

- Code compiled by GCC:

int main(void)
{
char a[] = "123";
char b[] = "abc";

printf("%p %p\n", a, b);

Cast ''a'' and ''b'' to void *.

>
return 0;
}

- Running it on AMD64 gives me:

0x7fff929c9410 0x7fff929c9400

- What is the reason for 16 bytes of distance between two address and
not just 8 bytes?

It''s an implementation detail that Standard C says nothing about. It may
be due to alignment reasons.


It''s an implementation detail that Standard C says nothing about. It may

be due to alignment reasons.

I know. Just curiosity about the election of 16 bytes over 8 (what I
expected).

Thanks anyway.


这篇关于在AMD64上简单分配两个缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆