0

Here, I have created a structure called directory. Which has double pointer to children and single pointer to parent.

    typedef struct {
        struct directory** children;
        struct directory* parent ; 
    }directory;

Here, I have created a function to add directory.

    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 ;
    }

I have defined a struct called directory which has double pointer to children and single pointer to parent directory. When I compile this I am getting warnings.

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]

I am not sure why am I getting this warnings ?

oz123
  • 27,559
  • 27
  • 125
  • 187
user2737926
  • 97
  • 1
  • 1
  • 9
  • `typedef struct {` --> `typedef struct directory {` or is `struct directorey` other place defined ? also `alloc_num_child` no member of `struct directorey`. – BLUEPIXY Apr 13 '14 at 21:24

1 Answers1

2

Look exactly at your struct declaration.

You declare a typedef named directory. You do not anywhere declare a struct directory. But you are using "struct directory" inside the untagged struct that you declare.

The compiler has no way to guess that you mean the typedef named "directory" when you write "struct directory".

I usually would write

typedef struct _directory {
    struct _directory** children;
    struct _directory* parent ; 
}directory;
gnasher729
  • 51,477
  • 5
  • 75
  • 98