CCPi-Regularisation-Toolkit icon indicating copy to clipboard operation
CCPi-Regularisation-Toolkit copied to clipboard

C functions should return int or void

Open paskino opened this issue 5 years ago • 3 comments

int would be better so that basic checks could be implemented

paskino avatar Apr 15 '19 14:04 paskino

@paskino not sure what you mean exactly? C functions currently return either zero or a pointer to an array. What do you mean by int?

dkazanc avatar Jun 02 '19 19:06 dkazanc

It's a good practice to return ints on C functions so that one can check the return value and decide if it run correctly: i.e. if return is 0 then OK, otherwise some problem.


int function(int a, float* b){

   ... 
  if (something goes wrong)
  return 1;
  ...
  if (something else goes wrong)
  return 2;

return 0;
}

If you want to return an array it'd be better to have it passed in the arguments.

paskino avatar Jun 03 '19 09:06 paskino

ok it makes sense. Will try to incorporate.

dkazanc avatar Jun 03 '19 13:06 dkazanc