Help...typedef struct...confusing...

This is a discussion on Help...typedef struct...confusing... within the C Programming forums, part of the General Programming Boards category; is'nt it the same?: Code: struct list { int data; struct list *link; }; typedef struct list NODE; typedef NODE ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    1

    Unhappy Help...typedef struct...confusing...

    is'nt it the same?:


    Code:
    struct list
    {
    int data; 
    struct list *link;
    };
    
    typedef struct list NODE;
    typedef NODE *theNode;


    with


    Code:
    typedef struct list
    {
    int data; 
    struct list *link;
    }NODE;
    
    NODE *theNode;


    isn't it the same? i'm getting lots of errors when i implement the second (typedef) into my Linked List below:



    heres what my lecturer did which i want to change:

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    /* the NODE structure */
    struct list
    {
    int data; //for each data enterd
    struct list *link;
    };
    
    typedef struct list theNode;
    typedef theNode *NODE; 
    void insertNode(NODE *, int );
    void printer(NODE);

    i just want to change it to:

    Code:
    typedef struct list
    {
    int data; 
    struct list *link;
    }NODE;
    
    NODE *theNode;

    i got lots of errors if i chage it, whats wrong??
    i hope u guys help me

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >isn't it the same?
    No, not at all. The typedef for struct list is the same, but there are two typedefs in the first example and only one in the second. That's not equivalent semantics.

    This creates a synonym for a pointer to a NODE:
    Code:
    typedef NODE *theNode;
    and this creates a pointer to a NODE:
    Code:
    NODE *theNode;
    See if you can find the error now.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. differences between struct and typedef struct
    By stanlvw in forum C Programming
    Replies: 1
    Last Post: 07-22-2008, 03:28 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  5. typedef struct question
    By flevine100 in forum C Programming
    Replies: 1
    Last Post: 09-03-2002, 09:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21