问题描述
- 由GCC编制的代码:
int main(无效)
{
char a [] =" 123" ;;
char b [] =" abc";
printf("%p%p \ n",a,b) ;
返回0;
}
- 在AMD64上运行它给了我:
0x7fff929c9410 0x7fff929c9400
- 两个地址和
之间的16字节距离不仅仅是8个字节的原因是什么?
询问gcc实现者。是他们决定编译器应该如何分配空间,而不是C语言本身。
C不需要16字节分隔,但不是
禁止它。
-
Eric Sosman
lid
将'a''和'b''置为无效*。
这是标准C未提及的实现细节。由于对齐原因,它可能是b $ b。
我知道。只是对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?
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
Cast ''a'' and ''b'' to void *.
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上简单分配两个缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!