我仍然是C的noob。我經常使用它,但通常不使用C的指針特性。我正在嘗試做什麼是指向已存在於函數內的本地空間中的結構的指針。我有這樣的代碼:C中的指針以及如何通過局部變量作爲指針
struct WorldCamera p_viewer;
struct Point3D_LLA p_subj;
struct Point2D_CalcRes p_res;
p_viewer.hfov = 25;
p_viewer.vfov = 25;
p_viewer.p.lat = 10.0f;
p_viewer.p.lon = 10.0f;
p_viewer.p.alt = 100.0f;
p_subj.lat = 9.98f;
p_subj.lon = 10.0f;
p_subj.alt = 100.0f;
// Do something interesting here.
compute_3d_transform(&p_viewer, &p_subj, &p_res, 10000.0f);
// Do something interesting here.
compute_3d_transform的原型是這樣的:
void compute_3d_transform(struct WorldCamera *p_viewer, struct Point3D_LLA *p_subj, struct Point2D_CalcRes *res, float cliph);
我想知道,如果我有這個權利。我正在編寫一個小型微控制器,我認爲它沒有太多的內存保護。破壞一塊內存可能會在未來造成奇怪的錯誤,這將很難調試。我試圖避免使用malloc/calloc函數,因爲這些需要專用的堆。
看起來像你找到了我。 – sizzzzlerz 2010-11-28 17:32:27