1. 程式人生 > >C語言除錯的四種方式

C語言除錯的四種方式

一. 編譯器警告:

1. 預設, 編譯器不生成所有警告。

2.使用 gcc -Wall

二. printf語句

1.Print to stderr instead of stdout

        •fprintf(stderr, ….)

三. assert

"assert" macro provided by standard library

        •Prints error message to stderr and terminates execution if assertion fails

四. 除錯工具 gdb

        •By adding “-g” option to your cc/gcc compile & link commands 
        •Better yet, add “-g” to the CFLAGS variable defined in Makefile