When calling a function, add "(void)" before the function name

We know that when defining a function, the "void" added to the function name means that the function has no return value. But what is the effect of adding "(void)" to the function name when calling it?
  The most obvious point is that the program does not care what the return value is after calling the function, such as the function strcpy, we directly use the form of "strcpy(des_str, src_str);" to call. "(void)strcpy(des_str, src_str);" is really rare!
  The reason is that this way of writing is not aimed at people, nor at the compiler, but at the static code detection tool, which uses the return value of the function as a detection criterion. In some large companies, more emphasis is placed on code specification, if this item needs to be checked during code static detection. In this case, it is necessary to use the form of "(void)" before the called function (name) to tell the static code detection tool that the return value of the function is not not processed, but that it does not need to be processed ( The return value of the function), there is no need to perform this check on the code here. In fact, this is the same reason we use "#pragma warning (disable: XXXX)" in our code.

For example, in CC2650 GAPRole initialization, execute VOID GAPRole_StartDevice(&hidDev_PeripheralCBs);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325748945&siteId=291194637