2014-04-13 4 views
0

여기에 directory라는 구조체를 만들었습니다. 어떤 자식에 대한 이중 포인터와 부모에 대한 단일 포인터가 있습니다.C 언어에서 컴파일 타임 경고 더블 포인터

여기에 디렉토리를 추가하는 기능을 만들었습니다.

directory* add_dir (char* name , char* path , directory* parent) { 

     directory* d = malloc (sizeof (directory)) ; 
     memset (d , 0 , sizeof(directory)) ; 
     //WARNING by line below 
     d->children = (directory**)malloc (sizeof(directory*) * DIR_COUNT) ; 
     memset (d->children , 0 , sizeof(directory*) * DIR_COUNT) ; 
     //WARNING by line below 
     d->parent = (directory*) parent ; 
      //Wanrning by line below 
      parent->children[parent->alloc_num_child] = (directory*) d ; 
    } 

나는 아이들과 부모 디렉토리에 하나의 포인터 이중 포인터를 가지고있는 구조체라는 디렉토리를 정의했습니다. 이것을 컴파일하면 경고가 표시됩니다.

Warnings : 


warning: assignment from incompatible pointer type [enabled by default] 
warning: assignment from incompatible pointer type [enabled by default] 
warning: assignment from incompatible pointer type [enabled by default] 

왜 내가이 경고를 받고 있는지 잘 모르겠습니까?

+0

'형식 정의 구조체를 작성합니다? 'alloc_num_child''struct directorey'의 멤버도 없습니다. – BLUEPIXY

답변

2

구조체 선언을 정확하게보십시오.

이름이 typedef 인 디렉토리를 선언합니다. 구조체 디렉토리를 선언하지 않습니다. 하지만 선언 한 태그없는 구조체 내부에서 "struct directory"를 사용하고 있습니다.

컴파일러는 "struct directory"를 쓸 때 "directory"라는 typedef를 의미한다는 것을 추측 할 수있는 방법이 없습니다. > '형식 정의 구조체 디렉토리 {`또는`구조체 directorey` 다른 곳 정의 -

나는 보통 {`

typedef struct _directory { 
    struct _directory** children; 
    struct _directory* parent ; 
}directory; 
+0

고마워요. 매우 도움이됩니다. – user2737926