定义 "needs to be at least XX bytes long" 是否包含空终止符,还是应该使用 XX+1?
Does the definition "needs to be at least XX bytes long" include the null terminator, or should I use XX+1?
我想知道,当您看到一个 API 说字符缓冲区应该 至少 XXX 字节长时,它是否包括空终止字符?
并不是说我介意节省一个字节,但是这件事让我很烦......(这里没有双重含义!)
来自 Mac OS if_indextoname
的 X 联机帮助页:
The if_indextoname() function maps the interface index specified in ifindex to it corresponding name,
which is copied into the buffer pointed to by ifname, which must be of at least IFNAMSIZ bytes.
字符缓冲区是一个 NUL
终止字符串。因此缓冲区需要足够大以容纳字符串,包括 NUL
.
我想知道,当您看到一个 API 说字符缓冲区应该 至少 XXX 字节长时,它是否包括空终止字符? 并不是说我介意节省一个字节,但是这件事让我很烦......(这里没有双重含义!)
来自 Mac OS if_indextoname
的 X 联机帮助页:
The if_indextoname() function maps the interface index specified in ifindex to it corresponding name, which is copied into the buffer pointed to by ifname, which must be of at least IFNAMSIZ bytes.
字符缓冲区是一个 NUL
终止字符串。因此缓冲区需要足够大以容纳字符串,包括 NUL
.