What's the use of memset() return value?

后端 未结 4 1207
无人共我
无人共我 2020-12-15 02:16

memset() is declared to return void* that is always the same value as the address passed into the function.

What\'s the use of the return v

4条回答
  •  粉色の甜心
    2020-12-15 03:02

    I came across this question when Googling to see what memset returned.

    I have some code where I test for one value, then if that is true test to see if a value is zeros.

    Because there is no completely portable way in C to test for zeros I have to run memset in the middle.

    So my code is:

    if ( a==true && (memcmp(memset(zeros, 0, sizeof(zeros)), b, sizeof(zeros)) == 0) )
    

    This speaks to the chaining purpose listed in the previous questions, but it is an example of a use for this technique.

    I'll leave it to others to judge if this is good coding or not.

提交回复
热议问题