0

I have two header files in the header directory of project , namely list.h and list-interface.h which contains the declaration of data types and declaration of functions on that data types,respectively.

//list.h   

typedef struct Container{
       int item;
       struct Container *next;
}node;

//list-interface.h

 node *first(node *);
 ......
  //some other declarations.

Then in the resource directory i have list-methods.c.   

//list-=methods.c  

 int is_last(node *lis_ptr, node *nod_ptr)
 {
    int islast = 0;
    if (nod_ptr == last(lis_ptr))
    islast = 1;
    return islast;
 }

 //returns 1 if the second argumented pointer points to the first element of the list,pointed by first argumented pointer.other wise 0.

 int is_first(node *lis_ptr, node *nod_ptr){
      int isfirst = 0;
      if (nod_ptr == first(lis_ptr))
          isfirst = 1;
      return isfirst;
  }

  //accessor methods------------------------------

  //returns the pionter to first element in the list.

  node* first(node *lis_ptr)
  {
      return lis_ptr;
  }

  //returns the pointer to last element in the list.

  node *last(node *lis_ptr)
  {
      while (lis_ptr->next != NULL)
      lis_ptr = lis_ptr->next;
      return lis_ptr;
  }


//This returns the pointer to the previous element to the node pointed by nod_ptr (second argument) in the list.

 node *before(node *first_ptr, node *nod_ptr)
 {

     if (first_ptr == nod_ptr){
        return NULL;
     }
     else{
        while (first_ptr->next != nod_ptr)
        first_ptr = first_ptr->next;
     }

    return first_ptr;

 }

But when i compile the code for list-methods.c in visual studio 2013 i get the following error

node*(node *) differs in level of indirection from int().

please provide me with some solution.

OldSchool
  • 2,123
  • 4
  • 23
  • 45
  • The error is not found in the posted code, please post the rest `// some other methods are defined`... – Iharob Al Asimi Jan 17 '15 at 20:20
  • http://stackoverflow.com/questions/11166833/differs-in-levels-of-indirection-from-int-c – BLUEPIXY Jan 17 '15 at 20:25
  • @iharob ok i have edited – OldSchool Jan 17 '15 at 20:25
  • @BLUEPIXY i am not getting it, the names are very odd...please if you can explain. – OldSchool Jan 17 '15 at 20:26
  • Perhaps, it is the actual function and different that error message is that type is interpreted as an automatic type you are using before the type of the correct function is referenced. To be checked whether such in can correct reference to the previous use of the prototype in the header file. – BLUEPIXY Jan 17 '15 at 20:31
  • 1) a '-' should not be used in file names, suggest using '_' 2) the source files seem to be missing: '#include "list-interfaces.h" and #include "list.h" – user3629249 Jan 17 '15 at 20:52

1 Answers1

0

To spell out what @BLUEPIXY and the previous question are saying: if you call a function like node* first() before you have declared the function, or its prototype, the compiler assumes it will be a function that returns int. Make sure you have all compiler warnings enabled and deal with every one.

Weather Vane
  • 33,872
  • 7
  • 36
  • 56