Valgrind Errors on Mac OS X for printf a double

后端 未结 1 660
暖寄归人
暖寄归人 2020-12-11 22:29

At the moment I am learning C with the awesome learncodethehardway series. I encountered the following:

I compile the following code and everything looks totally fin

相关标签:
1条回答
  • 2020-12-11 23:28

    Unfortunately, the libraries that printf uses, do not always behave in an ideal way. Valgrind will notice all errors - not only the ones you made, but every error made in the standard C library implementation on OSX, for instance.

    Some of those "errors" may be actual bugs (which is pretty rare), others are likely little shortcuts the library developers took, which may not look completely correct to Valgrind. One such thing is to rely on the operating system to clear and free all left over memory when a program exits - when in a pedantic world, the program should free all of its memory before exit. However, this stopped being strictly necessary somewhere around the days of DOS and AmigaOS.

    I am not saying this is necessarily what you are seeing in that error, but that you need to be mindful of what Valgrind says.

    To use Valgrind in practice, you may want a suppression file, which removes error messages related to system libraries. Here is a somewhat recent (January 2015) blog post about this issue which came about exactly because of "learning C the hard way" on OSX.

    0 讨论(0)
提交回复
热议问题