<分区>
将0
传递给memcpy()
是否有问题:
memcpy(dest, src, 0)
请注意,在我的代码中,我使用的是变量而不是 0
,它有时可以评估为 0
。
<分区>
将0
传递给memcpy()
是否有问题:
memcpy(dest, src, 0)
请注意,在我的代码中,我使用的是变量而不是 0
,它有时可以评估为 0
。
最佳答案
正如人们可能对一个理智的界面所期望的那样,零是一个有效的大小,并且不会导致任何事情发生。 C99 7.21.1/2 中各种字符串处理函数(包括 memcpy
)的规范特别允许:
Where an argument declared as
size_t n
specifies the length of the array for a function,n
can have the value zero on a call to that function. [...] On such a call, a function that locates a character finds no occurrence, a function that compares two character sequences returns zero, and a function that copies characters copies zero characters.
关于c++ - 这是允许的 : memcpy(dest, src, 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30506782/