M
Mike
Consider the following code:
"""
struct person {
char *name;
int age;
};
typedef struct person* StructType;
/* Think I got that syntax right above... */
void somefunc(StructType t)
{
// do something
}
int main()
{
StructType st;
somefunc(st);
}
"""
My professor called me out on my invocation of somefunc() by saying that
I should be passing by reference instead. My response was "Well, it's
*really* a pointer anyways, so what does it matter?" Now that I think
about this, I guess you should always pass by reference because you may
not always know if something is represented as a pointer. Is this the
reason? I have done more C than C++ so by nature I tend to focus on
pointers
Thanks.
Mike
"""
struct person {
char *name;
int age;
};
typedef struct person* StructType;
/* Think I got that syntax right above... */
void somefunc(StructType t)
{
// do something
}
int main()
{
StructType st;
somefunc(st);
}
"""
My professor called me out on my invocation of somefunc() by saying that
I should be passing by reference instead. My response was "Well, it's
*really* a pointer anyways, so what does it matter?" Now that I think
about this, I guess you should always pass by reference because you may
not always know if something is represented as a pointer. Is this the
reason? I have done more C than C++ so by nature I tend to focus on
pointers
Thanks.
Mike