seeking some advice here.
I have a structure which contains a pointer to another structure, something like this:
struct item
{
int type;
struct user *owner;
};
I also have accessor functions, like this:
int item_get_type(const struct item * i);
struct user * item_get_owner(const struct item * i);
My question is about the second of these functions: Does this violate any rules or best practices with regard to the use of const?
The reason I use const here is to signify that the accessor function will not modify the structure passed in to it, but the caller is allowed to modify the returned structure. Am I better off dropping the const in the argument?
It’s absolutely fine, and it correctly indicates your stated intention.