在linux中使用c语言编程时,errno是个很有用的动动。他可以把最后一次调用c的方法的错误代码保留。但是如果最后一次成功的调用c的方法,errno不会改变。因此,只有在c语言函数返回值异常时,再检测errno。

代码:

errno = 0;
int s = sqrt(-1);
if (errno) {
printf("error: %s\n", strerror(errno));
}

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2021-07-02
  • 2021-12-04
  • 2022-01-14
  • 2022-12-23
  • 2021-09-29
  • 2022-01-17
猜你喜欢
  • 2021-10-15
  • 2021-10-03
  • 2021-11-08
  • 2022-01-07
  • 2021-07-17
  • 2021-12-01
  • 2022-12-23
相关资源
相似解决方案