回覆列表
  • 1 # 使用者7328111544487

    自從看了《Unix/Linux程式設計實踐教程》(五星推薦這本書),檢視標頭檔案和函式資訊非常方便。

    man -k keyword | grep "name" 查詢一個man手冊中的簡短說明包含keyword的函式,name為函式名的關鍵字(可以不加管道)如 man -k timer | grep "set" 查詢一個man手冊中的簡短說明包含timer的函式,set為函式名的關鍵字(可以不加管道),可以查詢到以下資訊:getitimer (2) - get or set value of an interval timersetitimer (2) - get or set value of an interval timertimer_settime (2) - arm/disarm and fetch state of POSIX per-process timertimerfd_settime (2) - timers that notify via file descriptorstimerisset (3) - timeval operations函式呼叫任君選擇。

    grep "keyword" /usr/include/*.h | grep "typedef"grep "keyword" /usr/include/*/*.h | grep "typedef"如 grep "time_t" /usr/include/*.h | grep "typedef"可以查詢到 " typedef __time_t time_t; "

    以上方法可以查詢關鍵字為keyword的結構體、型別、函式原型的定義,typedef可以替換為define嘗試查詢,幾次重複查詢找到的定義,就能最終確定。

    locate keyword.h 可以查詢名為keyword的標頭檔案所在的目錄樹

    如 locate time.h | grep "/usr/include" 可以查詢到一下資訊:

    /usr/include/time.h

    /usr/include/utime.h

    /usr/include/i386-linux-gnu/bits/time.h

    /usr/include/i386-linux-gnu/sys/time.h

    /usr/include/linux/time.h

    /usr/include/linux/utime.h

    /usr/include/linux/netfilter/xt_time.h

    /usr/include/python2.7/datetime.h

    標頭檔案任君選擇。

    從此在linux下程式設計,查詢函式原型、標頭檔案、型別定義方便多了。

  • 中秋節和大豐收的關聯?
  • 教育的特點?