Because it is always easier to see the code ...
My parser populates this object:
typedef struct pair { char* elementName; char* elementValue; } pair;
My interpreter wants to read this object and populate it:
typedef struct thing { char* label; } thing;
Should I do this:
thing.label = pair.elementName;
or that:
thing.label = (char*)malloc(strlen(pair.elementName)+1); strcpy(thing.label, pair.elementName);
EDIT: Yes, probably I should have indicated what the rest of the program will do with objects. Ultimately, I will need to save the “pair” in the file. Therefore, when thing.label is changed, then (at some point) the name of the .elementName pair must be changed to match. So, I think the first is the best way to do this?
source share