[問題] 如何不讓printf轉成puts

看板C_and_CPP作者 (一直飛)時間6年前 (2019/04/03 22:12), 6年前編輯推噓4(406)
留言10則, 7人參與, 6年前最新討論串1/1
通常 C compiler 會做類似下面的轉換 printf("hello world\n") => puts("hello world"); 小弟我想問下gcc和clang分別該下什麼flag 才能阻止上面的轉換 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.222.49 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1554300768.A.91A.html ※ 編輯: flypaper (111.251.222.49), 04/03/2019 22:15:12

04/03 22:30, 6年前 , 1F
XY problem?
04/03 22:30, 1F

04/03 22:30, 6年前 , 2F
04/03 22:30, 2F
事情來由如下: 我工作遇到一個問題,就是前人的程式寫了一堆printf()來debug。 但是那支我常常需要放好幾天或背景執行,我是無法一直盯著螢幕看的。 所以我試圖利用動態連結來改變原本printf()的行為 (https://github.com/fakepaper56/print_to_log) 卻發生了我問的狀況。

04/04 00:05, 6年前 , 3F
如果是我會用tee或是檔案重導印到檔案耶......
04/04 00:05, 3F

04/04 03:23, 6年前 , 4F
硬要用這招的話,順便把puts改掉不就好了...
04/04 03:23, 4F
確實要改就全部改 畢竟當初搞不好有寫訊息是用puts()做的

04/04 03:24, 6年前 , 5F
其實gcc本身就有提供自訂printf
04/04 03:24, 5F

04/04 03:38, 6年前 , 6F
-fno-builtin-printf
04/04 03:38, 6F
※ 編輯: flypaper (111.251.222.49), 04/04/2019 07:35:08

04/05 23:52, 6年前 , 7F
改成fprintf,印到硬碟裡
04/05 23:52, 7F

04/06 00:14, 6年前 , 8F
就把puts順便hook掉啊
04/06 00:14, 8F

04/06 07:55, 6年前 , 9F
syscall 也順便啊><
04/06 07:55, 9F

04/18 16:10, 6年前 , 10F
freopen
04/18 16:10, 10F
文章代碼(AID): #1SfBzWaQ (C_and_CPP)