A struct is several bytes long, and you'd need to add in the cost of getline's return value as well. These values have to be pushed onto the stack, and then pulled back off and copied again into the receiving struct. That costs valuable processor cycles, but also it's a hidden cost that's not intuitive from reading the code, and therefore goes against C's design.
What might have been better is you have passed in a pointer to a struct, which would have involved fewer pushes and pops to stack - though with modern calling conventions the function arguments and return are in registers anyway, I think.
A
struct
is several bytes long, and you'd need to add in the cost of getline's return value as well. These values have to be pushed onto the stack, and then pulled back off and copied again into the receivingstruct
. That costs valuable processor cycles, but also it's a hidden cost that's not intuitive from reading the code, and therefore goes against C's design.What might have been better is you have passed in a pointer to a
struct
, which would have involved fewer pushes and pops to stack - though with modern calling conventions the function arguments and return are in registers anyway, I think.The cost is not intuitive, I see.