我無法理解c頭文件和源文件。我有:製作庫:標題和源文件中的衝突類型
something.c
#include <stdio.h>
#include "something.h"
typedef struct {
int row, col;
} point;
point
whereispoint(point **matrix, int rows, int cols)
{
..... Does something ....
printf("something...");
}
something.h
typedef struct point * p;
p whereispoint(p **matrix, int rows, int cols);
的main.c
#include <stdio.h>
#include "something.h"
int
main(void)
{
int row, col;
p **matrix=malloc(bla, bla);
.....Something.....
p=whereispoint(matrix, row, col);
return 0;
}
現在,當我實際上並不知道ho w至編譯這個......我想gcc -c main.c something.c
但不工作,我試圖編譯單獨gcc -c main.c
和gcc -c something.c
然後的main.c的作品,但something.c沒有。
我實際上正在嘗試使用某些東西來創建一個庫,但是因爲我甚至無法將它編譯爲目標代碼,所以我不知道該怎麼做。我想有一些錯誤的結構類型,且它在something.h typedef的,但我想不出什麼...
不透明類型沒有任何問題。如果功能的調用者不需要知道結構內部是什麼,爲什麼要公開它? C只需要知道操作結構實例的函數內部的實現。 @hmhd的解決方案更好。 –
@WilliamMorris - 不,不透明類型沒有問題。標準C庫中有相當少的不透明類型。但是除非你願意編寫合適的訪問器並付出一些痛苦來確保用戶永遠不必真正關心你的不透明類型,否則最好不要這樣做。 – Vatine