Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 10
    @JohnR.Strohm I tried it and it actually works. A function can return a struct.... So what is the reason is not done? Commented Oct 19, 2017 at 14:01
  • 28
    Pre-standardization C did not allow structs to be copied or to be passed by value. The C standard library has many holdouts from that era that would not be written that way today, e.g. it took until C11 for the utterly misdesigned gets() function to be removed. Some programmers still have an aversion to copying structs, old habits die hard. Commented Oct 19, 2017 at 14:12
  • 27
    FILE* is effectively an opaque handle. User code should not care what its internal structure is. Commented Oct 19, 2017 at 15:39
  • 3
    Return by reference is only a reasonable default when you have garbage collection. Commented Oct 19, 2017 at 19:02
  • 7
    @JohnR.Strohm The "very senior" in your profile seems to go back before 1989 ;-) -- when ANSI C permitted what K&R C didn't: Copy structures in assignments, parameter passing and return values. K&R's original book indeed stated explicitly (I'm paraphrasing): "you can do exactly two things with a structure, take its address with & and access a member with .." Commented Oct 19, 2017 at 20:17