根据这份Unix文档 http://pubs.opengroup.org/onlinepubs/009695399/functions/bzero.html,
The memset() function is preferred over bzero().
For maximum portability, it is recommended to replace
the function call to bzero() as follows:
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
但是void *memset(void *s, int c, size_t n);
的第二个参数是一个int,那么为什么他们建议使用 '\0' 而不是 0?memset()文档说:“memset()函数应该将c(转换为无符号字符))参数复制到s指向的对象的前n个字节中。” 这样做是更有效还是更明确? 这里是否涉及最佳实践?
'\0'
是一个整型变量。不过,你使用什么类型并不重要。 - chris0
转换为'\0'
是否可能存在任何问题) - Xarn'\0'
不是char
类型,它是一个int
类型。 - chux - Reinstate Monica