0

I have the following piece of code:

typedef struct Folder{
 void (**vtable)();
 struct Set *ns;
}Folder;

Node *newFolder(char *n,struct Set *ns);

When I compile this file, it gives me:

passing argument to parameter 'ns' here
Node *newFolder(char *n,struct Set *ns);

Here is my test unit for this:

  void testFolderNrNodes(CuTest *tc) {
  Node_reset();
  Node* folder = newFolder("folder_to_test", SetNil());
  CuAssertIntEquals(tc, 1, nrNodes(folder));
}

which gives me this error:

incompatible integer to pointer conversion passing 'int' to parameter of type
'struct Set *' [-Wint-conversion]
Node* folder = newFolder("folder_to_test", SetNil());
                                           ^~~~~~~~

I don't see what the problem is. Does it come from the struct Set *ns? Why do I get this message with "incompatible integer to pointer conversion passing 'int' to parameter of type 'struct Set *"? Can someone please let me know what I am doing wrong?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
S. N
  • 3,456
  • 12
  • 42
  • 65
  • 1
    What is `struct Set` (and `Node`)? Are you sure you didn't mean `struct Folder` when you use `struct Set`? The `SetNil()` problem appears to be that you've not declared the function, so by context the C compiler assumes it is a function returning an `int`. – Jonathan Leffler Mar 01 '14 at 20:31
  • 1
    Please update your question to include the definition of `SetNil()`. – Lee Duhem Mar 01 '14 at 20:35
  • It looks like SetNil() returns a int, instead of a pointer to struct Set. As @leeduhem has mentioned, please include the definition of SetNil(), that will help in solving the issue – Joe Mar 01 '14 at 20:43
  • @Joe, i dont have any definition for SetNil(). the test unit comes from another file and my job is to write the function and they should pass the test. The assignment doesnt sy anything about SetNil(), I thought its declared automatically. here is another example that gives me warning: warning: incompatible integer to pointer conversion initializing 'struct Set *' with an expression of type 'int' [-Wint-conversion] Set* set1 = SetNil(); – S. N Mar 01 '14 at 20:49
  • @leeduhem please look up. – S. N Mar 01 '14 at 20:49
  • is this clear why there is not definition for setNill() is the type that I am using correct. – S. N Mar 01 '14 at 20:50
  • @S.N Because you cannot offer the information, the only thing that I can do is guess according to the warnings. It looks like your `SetNil()` gives you a `int`, but you also have `struct Set`, this inconsistency confused me totally. Then my only option is to wish you luck, so good luck. – Lee Duhem Mar 01 '14 at 20:57

2 Answers2

1

Your SetNil() function either returns an integer or has not been declared before its use (in which case the compiler will assume it returns an integer). newFolder() however is expecting its second parameter to be a struct Set *.

abligh
  • 24,573
  • 4
  • 47
  • 84
0

From your comment, it is clear that the SetNil() is indeed returning an int. If you really want to avoid the warning then you can change the code to

newFolder("folder_to_test", (struct Set *)SetNil())

However, that could be really dangerous, unless you can know what SetNil returns. The real fix should be in the function SetNil()

Joe
  • 1,312
  • 20
  • 24