I have a typedef int my_type and i have a function which looks like
void my_func (my_type* x);
How should I use this func to modify x using the best practice?
I have a typedef int my_type and i have a function which looks like
void my_func (my_type* x);
How should I use this func to modify x using the best practice?
You can use the dereferencing operator '*' in your function :
void my_func (my_type* x)
{
assert(x); // To protect from NULL pointer as mentioned in com.
*x = 5; //for example
}
If you want to modify by assignment use claferri's answer. If you want to modify a member (if my_type is a struct) do:
void my_func(my_type* x) {
x->member = 5;
}
If you use typedef you basically create a new type. As with all other types, just use the type like any other one. Just make sure to be consistent with typed -- if you use my_type for a variable use it everywhere for that variable. If you pass that type to a function use that type in the function, even if you know that the type is simply an int. And so on ...