Error handling strategies in a shared library - C

前端 未结 4 1165
野的像风
野的像风 2021-02-14 10:40

I am writing a cross platform shared library (.so in linux and .dll in windows) using C. Currently when there is a error, library functions returns the

4条回答
  •  旧巷少年郎
    2021-02-14 11:16

    In general, you shouldn't be writing to stdout at all from your library - even in a console application that could corrupt the output that the application is producing. stderr is a little more forgivable, but you still shouldn't really use that unless the application requests it.

    The OpenSSL is a cross-platform shared library that had much the same problem to solve. Their method has the library record detailed error information in an internal error queue, which the application can request when an error return value is seen and then present to the user in whichever way is appropriate. (It also provides a convenience function that dumps the entire error queue to a FILE *).

提交回复
热议问题