문제

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?

도움이 되었습니까?

해결책

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top