作者meltice (三亿两千万大散户)
看板C_and_CPP
标题Re: [问题] 为什麽作业系统都用C写? 而不用C++呢?
时间Sat Mar 7 20:25:57 2009
回应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)