Question

i have to use exit(1) command in a function. Does it have anything to do with the return data type of the function in which it is being used?

Était-ce utile?

La solution

No. The exit function never returns but instead terminates the process it's called from. The C compiler has no intuitive understanding of it and treats it like any other void returning function.

This does mean though that while exit will end your function the C compiler doesn't see it that way. Hence it will still want a valid return else it will spit out warnings /errors (with a high enough error level enabled). But this is easy enough to work around

int myFunc() {
  ...
  exit(exitCode);
  return 42;  // Never hit but keeps C compiler happy
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top