Skip to content

Instantly share code, notes, and snippets.

@prufrock
Last active December 30, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prufrock/7845995 to your computer and use it in GitHub Desktop.
Save prufrock/7845995 to your computer and use it in GitHub Desktop.
keeps warning me "initialization from incompatible pointer type [enabled by default]"
#include "linkedlist.h"
int_node linked_list(int data, int_node *link)
{
int_node l = {data, link};
return l;
}
typedef struct int_node { int data; // The elemnent stored in this node struct int_node *link; // Refers to the next node in the list } int_node; int_node linked_list(int data, int_node *link);
#include "linkedlist.h"
#include <stdio.h>
int main()
{
puts("loaded");
}
@prufrock
Copy link
Author

prufrock commented Dec 7, 2013

keeps warning me "initialization from incompatible pointer type [enabled by default]"

@prufrock
Copy link
Author

prufrock commented Dec 7, 2013

I fixed the issue in the previous commit by adding a proper name to the struct 'int_node' rather than just giving it a type_def name. It turns out a struct has to have a proper name when it refers to itself.

@prufrock
Copy link
Author

prufrock commented Dec 7, 2013

I can't compile the code due to the error: "linkedlist.h:1:1: error: unknown type name ‘int_node’":
https://gist.github.com/prufrock/7845995/fe8a918d5143b24501f0be2226d100b96946825c

@prufrock
Copy link
Author

prufrock commented Dec 7, 2013

I fixed the compile error by adding the struct to the header file in this commit: https://gist.github.com/prufrock/7845995/e89aa648eb9e6de2a04505526b8557c2c774e61a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment