問題:
Presuming that your C++ compiler supports them, is there any particular reason not to use __FILE__
, __LINE__
and __FUNCTION__
for logging and debugging purposes?假設您的 C++ 編譯器支持它們,是否有任何特殊原因不使用__FILE__
、 __LINE__
和__FUNCTION__
進行日誌記錄和調試?
I'm primarily concerned with giving the user misleading data—for example, reporting the incorrect line number or function as a result of optimization—or taking a performance hit as a result.我主要關心的是向用戶提供誤導性數據——例如,報告不正確的行號或作爲優化結果的函數——或者因此而導致性能下降。
Basically, can I trust __FILE__
, __LINE__
and __FUNCTION__
to always do the right thing?基本上,我可以相信__FILE__
、 __LINE__
和__FUNCTION__
總是做正確的事嗎?
解決方案:
參考一: https://en.stackoom.com/question/2VKI參考二: https://stackoom.com/question/2VKI