How would you do a functionally pure linked list in C? Is a linked list what I should even be doing? I'm trying to have a list of objects but I can't think of how to add an item to the list from a function without modifying outside states.
I basically want this:
void AddItemToList(Item item);
To be able to be called from anywhere, without the caller having to worry about what list is being added to.
Right now I just have:
void AddTypeToList(entityType_t *type, entityType_t *listHead)
{
type->next = listHead;
listHead = type;
}
void RegisterEntityType(entityType_t *type)
{
AddTypeToList(type, typeList);
}
But this is obviously not functional (or is it?) because RegisterEntityType is modifying typeList. (which is a global entityType_t)