一千萬個為什麽

搜索

標準錯誤報告


像gcc,rm,cp等常見程序似乎遵循報告錯誤的模式,如下所示:

程序:錯誤

例如:

$ gcc
gcc: no input files

我是否應該從我自己的C程序中調用一些標準函數或宏來以標準方式報告錯誤?

最佳答案

It dates back to the earliest days of Unix programming. It was always a recommendation that error messages be prefixed by the name of the command generating them, not least so that if errors occur in a pipeline of commands, you can tell which of the various commands generated the error message. You can see the style in K&R 1st Edition, in some of the example programs (not quite all), and also in 'Software Tools' by Kernighan & Plauger, and in 'The UNIX Programming Environment' by Kernighan & Pike.

對於此類錯誤消息,沒有完全標準的工具 - 函數或宏。 (我有一套廣泛而全面的錯誤報告功能,可以在消息之前打印程序名稱。)

轉載註明原文: 標準錯誤報告

猜你喜歡