Consider this code:
struct s { /* ... */ };
void f(struct s x) { /* ... */) /* (1) */
/* or */
void f(const struct s *x) { /* ... */ } /* (2) */
When struct s has a decent size, in which case should we prefer the first form?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Are you asking which is better?
It depends what you are trying to do – the second form with a pointer will be more efficient. But if you just want to pass a value to
fand not have to worry about side-effects then you might go with the first signature – as long as thestructis not too large.