小编Cod*_*der的帖子

当 dest 小于 src 但又足够大以容纳 src 所需的子字符串时,为什么 strncpy() 会产生垃圾?

我尝试使用strncpy()限制复制到 dest (此处为str1 )的 n 字节数。\ndest 对于 n 字节来说足够大,但是当 dest 小于源时(此处为argv[1 ])。\n当我使 dest 足够大以容纳源时,这看起来有所不同。

\n

这是代码:

\n
#include <stdio.h>                                                              \n#include <string.h>                                                             \n                                                                                \nint main(int argc, char *argv[])                                                \n{                                                                               \n/* // Works when str1[?] is 20:                                                                    \n  char str1[20];                                                                \n  char str2[20]; */                                                             \n                                                                                \n  // produces garbage, str1 is smaller than argv[1] but big enough for the 4 bytes copied                                                            \n  char str1[10];                                                                \n  char str2[10];                                                                \n                                                                                \n  printf("argc = %i\\n", argc);                                                  \n  if (argc <= …
Run Code Online (Sandbox Code Playgroud)

c string strcpy strncpy

2
推荐指数
1
解决办法
336
查看次数

为什么 x86-32 架构没有在 x86-64 之前获得更多通用寄存器?

x86-32 架构确实有 8 x 32 位通用寄存器。它们是 EAX、EBX、ECX、EDX、ESI、EDI、ESP 和 EBP。

但为什么直到 x86-64 架构出现之后这个数字才翻倍呢?

如果你看看从 i386 到 Pentium 4 的 32 位 CPU 和软件世界,那么在 32 位时代,软件不再支持较旧的 32 位 CPU,因为使用了一些功能,只有较新的 32 位 CPU 才能使用这些功能。 CPU确实有。因此,问题是为什么不简单地提前增加通用寄存器的数量呢?

难道是因为Intel想要推动安腾架构,因此对x86架构的更多GPR不感兴趣?如果是这样,为什么 AMD 在 2003 年推出 AMD64 之前没有自己尝试呢?

x86 x86-64 cpu-architecture cpu-registers

1
推荐指数
1
解决办法
81
查看次数

标签 统计

c ×1

cpu-architecture ×1

cpu-registers ×1

strcpy ×1

string ×1

strncpy ×1

x86 ×1

x86-64 ×1