Interface file 작성하기 !!!!

lokee의 이미지

Code Sample

//prac.c
#include
#include
#include
#include "prac.h"

struct name {
int watever;

};

Code Sample

//prac.h
typedef struct name *Name;

Code Sample

//testPrac.c

#include
#include
#include
#include "prac.h"

int main(int argc, char* argv[]) {

int a[10][10];
a[5][7] = 42;

Name name1;
name1 = (Name) malloc(sizeof(struct name));

name1->watever = 3; //watever is int in the struct
printf("%d\n", name1->watever);

return 0;
}

이렇게 하니까 에러가 나옵니다

"dereferencing pointer to incomplete type"

이게 무슨뜻인가요?

pok의 이미지

완전적이지 않은 타입을 참조하고 있어서 나는 에러입니다.
prac.h 파일에 struct 의 정의도 같이 있어야 합니다.
//prac.h
struct name { int whatever; };
typedef struct name* Name;

정의/선언/자기참조구조체/ 등등으로 찾으시면 완전형/불완전형 개념을 잡을수 있으실 겁니다.

첨언하면, C에서 보통 struct tagging 과 typedef를 같이합니다.
typedef struct _name { int whatever; } name;
typedef name* Name;
sizeof(name);


poklog at http://poksion.cafe24.com/poklog/