Let’s assume I want to use a library that contains these 2 headers:
// types.h
typedef const char* Value;
typedef const char* Key;
// map.h
/** The given name and value will be copied into the map */
void add(struct Map* m, Key key, Value value);
I’m assuming the comment means that the contents of the char*s key and value will be copied by the add function, and it won’t store the pointers for use after it has returned. That means the calling function can do whatever it wants with those pointers, like e.g. freeing key and value, immediately after calling add.
The calling function can also expect that add will not modify key or value.
Now what would the experienced C programmer assume about these ownership issues if that comment wasn’t there and neither sources of the implementation nor a usage example were available?
First & foremost is to try & get the documentation. One cannot be 100% sure unless the API documents the behavior. If all attempts fail then it is reasonable to assume that:
KeyorValuesince they are passed asconst.KeyandValueafter the function call.Also, One should confirm the assumptions with rigorous testing.