Thread: Pointer Problems

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User TieFighter's Avatar
    Join Date
    Feb 2010
    Location
    La Crosse, WI
    Posts
    32

    Unhappy Pointer Problems

    I'm having issues understanding how to use pointers, or so my compiler is telling me. Anyway, I'm trying to simply take whatever Attributes are given to me in the parameters, malloc some space for them so they don't disappear at the end of the function, and then set the Attribute part of a SymEntry to reference that newly allocated space.

    Code:
    void SetAttr(struct SymEntry *AnEntry, void *Attributes) {
    	AnEntry->Attributes = malloc(sizeof(Attributes*));
    	AnEntry->Attributes = *Attributes;
    };
    While I'm at it, how do I retrieve that attribute?
    Code:
    void * GetAttr(struct SymEntry *AnEntry) {
    	void *Att = malloc(sizeof(AnEntry->Attributes));
    	Att = *(AnEntry-Attributes);
    	return Att;
    };
    This is probably really basic stuff to you guys, but I'm really lost here due to lack of any experience with pointers. Thanks in advance.

    oh and here are the errors cc is giving to me:
    SymTab.c: In function ‘SetAttr’:
    SymTab.c:113: error: expected expression before ‘)’ token
    SymTab.c:114: warning: dereferencing ‘void *’ pointer
    SymTab.c:114: error: void value not ignored as it ought to be
    SymTab.c: In function ‘GetAttr’:
    SymTab.c:119: error: ‘Attributes’ undeclared (first use in this function)
    SymTab.c:119: error: (Each undeclared identifier is reported only once
    SymTab.c:119: error: for each function it appears in.)
    Last edited by TieFighter; 02-18-2010 at 08:59 AM. Reason: Listing Errors

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with passing an array of structures by pointer
    By raptor1770 in forum C Programming
    Replies: 9
    Last Post: 11-29-2008, 11:01 AM
  2. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  3. Function and pointer problems
    By Dylancougar in forum C Programming
    Replies: 4
    Last Post: 11-14-2005, 08:59 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. base class pointer problems
    By ... in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2003, 11:27 PM