Re: [問題] 為什麼作業系統都用C寫? 而不用C++呢?
看板C_and_CPP (C/C++)作者meltice (三億兩千萬大散戶)時間16年前 (2009/03/07 20:25)推噓0(0推 0噓 0→)留言0則, 0人參與討論串16/37 (看更多)
回應littleshan
1.
in header file
struct FS
{
int (*remove)(const char *path);
};
#define FS(type) type##_fs
in local_fs.c
static int remove(const char *path){...}
struct FS local_fs;
local_fs.remove = remove;
in remote_fs.c
static int remove(const char *path){...}
struct FS remote_fs;
remote_fs.remove = remove;
Then you can call anywhere like,
struct FS *fsp = &FS(remote);
fsp->remove("filename");
2.
lock(r1);
if(...)
goto exit1;
lock(r2)
if(...)
goto exit2;
...
exit2:
unlock(r2);
exit1:
unlock(r1);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 115.83.188.241
※ 編輯: meltice 來自: 115.83.188.241 (03/07 20:34)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 16 之 37 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章