[問題] 動態連結程式庫實作

作者: peter98 (新兵)   2015-06-19 22:15:43
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
gcc, Linux
問題(Question):
在念 程式設計師的自我修養 一書中看到的 在第185頁
簡單說有兩支程式 他們都呼叫一個寫在Lib.h/Lib.c的函式foobar
(程式碼在下方)
然後下指令: gcc -fPIC -shared -o Lib.so Lib.c 來產生.so檔案
問題是:為什麼這邊的Lib.c不用include Lib.h???
程式碼(Code):(請善用置底文網頁, 記得排版)
// Lib.c
#include <stdio.h>
void foobar( int i )
{
// Do something;
}
// Lib.cpp
#ifndef LIB_H
#define LIB_H
void foobar( int i );
#endif
作者: kerwinhui (kezza)   2015-06-19 22:21:00
因為沒用到啊。要用到到『現在』還沒有出現的才要宣告
作者: Bencrie   2015-06-19 23:28:00
如果在 foobar 前面插入一個會用到 foobar 的 function你就會需要 header
作者: peter98 (新兵)   2015-06-20 10:57:00
了解 謝謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com