-
Cleaning up my code.
Hello, this is just me being a bit a perfectionist, but I was wondering if it's possible to make this snippet of code shorter and perhaps more efficient.
Code:
p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].symtype = p_newsym->symtype;p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].identifier = p_newsym->identifier;p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].data = p_newsym->data;p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].immutable = p_newsym->immutable;
p_sstack is a parameter of type sstack*, which is a struct containing members int size and slist* data. slist is a struct containing members int size and sym* data. sym is a struct containing members symtype* type, char* identifier, void* data and bool immutable. p_newsym is a parameter of type sym*.
-
P.S, I toughly apologize for the awful formatting of the code, it seemed to ignore all of my new-lines.
-
in my opinion - you do not need to make it shorter. you need to make it easier to follow.
Code:
data* tail = &p_sstack->data[p_sstack->size - 1];
data* tails_tail = &tail->data[tail->size - 1];
etc
with some self describing variable names
-
You can do this:
Code:
i = p_sstack->size - 1;
j = p_sstack->data[i].size - 1;
p_sstack->data[i].data[j] = p_newsym;