Liste des Groupes | Revenir à co vms |
On Thu, 22 Aug 2024 19:21:07 -0400I am often wrong so that is no big deal.
Arne Vajhøj <arne@vajhoej.dk> wrote:On 8/22/2024 7:12 PM, chrisq wrote:Just admit that you was wrongOn 8/21/24 19:13, Arne Vajhøj wrote:>On 8/21/2024 8:26 AM, chrisq wrote:>On 8/21/24 02:25, Lawrence D'Oliveiro wrote:>On Tue, 20 Aug 2024 09:47:36 -0400, Arne Vajhøj wrote:>Few languages support multiple return values.>
Even in C and Fortran, a function can return a struct.
Better to declare the struct externally, then pass a pointer
to it. Much tidier.
In C one should definitely return a pointer to struct and not
Problem is that of you return a pointer, that suggests that the
struct has been declared static inside the called function. That
would be a fail for reentant code that might be called from
elsewhere, say, from an interrupt handler, or another thread.
The struct would typically be on the stack or heap, and would
disappear on return from the call, making the return value
invalid. Ideally, in a multitasking os, all code should be
designed to be fully reentrant, to make it safe in all
situations.
My assumption would be that the struct was malloc'ed in
the function.
>
That obvious also has its problem. One can write in
72 point bold red blinking font that it is the callers
responsibility to call free and it will still be
forgotten in some cases.
and that the best option in C is the sameReturning the struct itself result in a copy of the struct. The
as in many other languages - return the structure itself.
Les messages affichés proviennent d'usenet.