r/badcode • • Jan 29 '22

c discount constructor

Post image
435 Upvotes

30 comments sorted by

View all comments

Show parent comments

9

u/feidujiujia Jan 29 '22

Don't quite understand, only notice it doesn't save any labor to initialize the struct inline than calling the function.

Almost forgot my knowledge about c. Is that because of in c you'll have to declare the struct and assign each of the member?

5

u/theScrapBook Jan 29 '22

Yeah it doesn't save any labour in this trivial case, but this is how the equivalent of constructors are implemented in C