memset不能填充数组(memset not filling array)
u32 iterations = 5;
u32* ecx = (u32*)malloc(sizeof(u32) * iterations);
memset(ecx, 0xBAADF00D, sizeof(u32) * iterations);
printf("%.8X\n", ecx[0]);
ecx[0] = 0xBAADF00D;
printf("%.8X\n", ecx[0]);
free(ecx);
简而言之,为什么我的输出结果如下?
0D0D0D0D BAADF00Dps:u32是一个简单的unsigned int类型定义
编辑:
用gcc编译4.3.4 包含string.h u32 iterations = 5; u32* ecx = (u32*)malloc(sizeof(u32) * iterations); memset(ecx, 0xBAADF00D, sizeof(u32) * iterations); printf("%.8X\n", ecx[0]); ecx[0] = 0xBAADF00D; printf("%.8X\n", ecx[0]); free(ecx);Very simply put, why is my output the following?
0D0D0D0D BAADF00Dps: u32 is a simple typedef of unsigned int
edit:
Compiling with gcc 4.3.4 string.h is included最满意答案
memset的第二个参数被键入为int,但实际上是一个无符号字符 。 0xBAADF00D转换为无符号字符(最低有效字节)为0x0D,因此memset用0x0D填充内存。
The second parameter to memset is typed as an int but is really an unsigned char. 0xBAADF00D converted to an unsigned char (least significant byte) is 0x0D, so memset fills memory with 0x0D.
更多推荐
发布评论