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.)