Thread: trouble with structs..

  1. #1
    Registered User
    Join Date
    Jan 2008

    trouble with structs..

    Given the code:

    typedef struct {
      int item;
      struct node *next;
    } node;
    main(int argc, char *argv[]) {
      node *n = malloc(sizeof(node));
      n->item = 5;
      n->next = n;
      return 0;
    (yes, I'm aware that in this configuration, the node will be pointing to itself).

    Why does gcc (OSX 10.5) report the following error:
    josephus.c: In function 'main':
    josephus.c:15: warning: assignment from incompatible pointer type


  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Did you ever define a struct node? You have an anonymous struct that you have typedef'ed as a node. Perhaps try
    typedef struct Node {
        int item;
        struct Node *next;
    } node;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  2. Replies: 7
    Last Post: 06-04-2008, 10:39 PM
  3. Replies: 41
    Last Post: 07-04-2004, 03:23 PM
  4. packed structs
    By moi in forum C Programming
    Replies: 4
    Last Post: 08-20-2002, 01:46 PM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM