1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 12:32:21 +00:00

Merge branch 'master' of github.com:chai2010/advanced-go-programming-book

This commit is contained in:
Xargin 2018-06-18 16:55:40 +08:00
commit b90de20cc3

View File

@ -42,7 +42,7 @@ func main() {
上面的div函数实现了一个整数除法的运算然后通过返回值返回除法的结果。
不过如果对于除数为0的情形并没有做特殊处理。如果希望在除数为0的时候返回一个错误时候返回正常的结果。因为C语言不支持返回多个结果因此`<errno.h>`标准库提供了一个`errno`宏用于返回错误状态。我们可以近似地将`errno`一个线程安全的全局变量,可以用于记录最近一次错误的状态码。
不过对于除数为0的情形并没有做特殊处理。如果希望在除数为0的时候返回一个错误时候返回正常的结果。因为C语言不支持返回多个结果因此`<errno.h>`标准库提供了一个`errno`宏用于返回错误状态。我们可以近似地将`errno`一个线程安全的全局变量,可以用于记录最近一次错误的状态码。
改进后的div函数实现如下