Thread: Request for member x in something not in a struct or union

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    Request for member x in something not in a struct or union

    I've searched for the forums and found many solutions to this problem. While solving it with my program has proven to be very difficult, the ones I did fix just created more errors.

    What I'm doing is created a linked list. Each node in the linked list contains a number from 0 - 9.

    This function works fine:

    Code:
    void emptyList(LIST_HEAD *list){
    	list->head = NULL;
    	list->size = 0;
    }
    However this does not, I get the 'Request for member x in something not in a struct or union' error here.

    Code:
    NODE *insertFirst(LIST_HEAD *list, DATA digit){
    	NODE node;
    	node.digit = digit;
    
    	if (list.head == NULL){		
    		node.next = NULL;
    		list.head = node;
    	}else{
    		node.next = list->head;
    		list->head = node;
    	}
    
    	list->size = list->size + 1;
    
    	return node;
    }
    My first question is how to return addresses to dynamic variables (or variables that are created every time the function is run) and not get a warning that its a local variable. I also have issues with the return statement with incompatible types. In any other language this would be easy for me to fix but for some reason this has me by the 'short hair and curlies' >.<

    Here is another example:

    Code:
    LIST_HEAD listHead;
    
    LIST_HEAD *createList(void){
        return &listHead;
    }
    This works but it doesn't have the intended use - how can I create an object of type LIST_HEAD (my own struct) and return the address to it without it being local variable?

    Any help is GREATLY appreciated
    Thanks,
    Lang

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    list isn't a struct or a union, as the compiler quite rightly mentions. It is, however, a pointer to a struct; if you want a member variable of a struct pointed to, that's what -> is for.

    As for the memory management, search on "malloc".

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    With malloc I need to know the size of my LIST_HEAD - but I don't know what that size its going to be...


    *edit* REALLY DUMB QUESTION! My bad lol
    Last edited by Lang; 03-17-2008 at 12:25 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  3. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM