Timeline for Why do many functions that return structures in C, actually return pointers to structures?
Current License: CC BY-SA 3.0
24 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 1, 2017 at 10:15 | answer | added | user204677 | timeline score: 4 | |
| Nov 16, 2017 at 1:55 | audit | First posts | |||
| Nov 16, 2017 at 1:56 | |||||
| Oct 25, 2017 at 3:29 | history | tweeted | twitter.com/StackSoftEng/status/923028842389934082 | ||
| Oct 20, 2017 at 18:01 | comment | added | Oskar Skog | Even though it turned out to be possible to do this, it might be a common belief that it's not possible. | |
| Oct 20, 2017 at 13:42 | history | protected | gnat | ||
| Oct 20, 2017 at 8:29 | answer | added | Basile Starynkevitch | timeline score: 13 | |
| Oct 20, 2017 at 7:16 | comment | added | pipe | @PeterA.Schneider Indeed, the current standard (paragraph 6.7.6.3) now only states "A function declarator shall not specify a return type that is a function type or an array type." | |
| S Oct 19, 2017 at 23:01 | history | suggested | user88637 | CC BY-SA 3.0 | typography/defluff |
| Oct 19, 2017 at 22:35 | answer | added | supercat | timeline score: 6 | |
| Oct 19, 2017 at 21:47 | review | Suggested edits | |||
| S Oct 19, 2017 at 23:01 | |||||
| Oct 19, 2017 at 20:17 | comment | added | Peter - Reinstate Monica | @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 .." | |
| Oct 19, 2017 at 19:02 | comment | added | Idan Arye | Return by reference is only a reasonable default when you have garbage collection. | |
| Oct 19, 2017 at 18:25 | answer | added | John Bode | timeline score: 68 | |
| Oct 19, 2017 at 15:59 | comment | added | Karl Bielefeldt | Nearly all languages don't even give you the choice, because returning by reference is a reasonable default. C's ability to return by value is much more rare and interesting. | |
| Oct 19, 2017 at 15:39 | comment | added | CodesInChaos | FILE* is effectively an opaque handle. User code should not care what its internal structure is. | |
| Oct 19, 2017 at 14:27 | history | edited | yoyo_fun | CC BY-SA 3.0 | edited title |
| Oct 19, 2017 at 14:12 | comment | added | amon | 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. | |
| Oct 19, 2017 at 14:05 | answer | added | Mason Wheeler | timeline score: 40 | |
| Oct 19, 2017 at 14:04 | answer | added | Ryan | timeline score: 6 | |
| Oct 19, 2017 at 14:02 | review | Close votes | |||
| Oct 20, 2017 at 12:45 | |||||
| Oct 19, 2017 at 14:01 | comment | added | yoyo_fun | @JohnR.Strohm I tried it and it actually works. A function can return a struct.... So what is the reason is not done? | |
| Oct 19, 2017 at 13:57 | comment | added | yoyo_fun | @JohnR.Strohm So it is not possible to return a variable that is of type struct something? I never tried it honestly. | |
| Oct 19, 2017 at 13:54 | comment | added | John R. Strohm | The C language does not allow this. It is not clear if you are asking why programs don't do it (the answer is the language doesn't allow it, so programs CAN'T do it), or why the language doesn't allow it. | |
| Oct 19, 2017 at 13:42 | history | asked | yoyo_fun | CC BY-SA 3.0 |