Deutsch English Français Italiano |
<vaa19c$tj3d$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=C3=B8j?= <arne@vajhoej.dk> Newsgroups: comp.os.vms Subject: Re: New VSI post on Youtube Date: Fri, 23 Aug 2024 09:02:36 -0400 Organization: A noiseless patient Spider Lines: 59 Message-ID: <vaa19c$tj3d$1@dont-email.me> References: <v9ehs5$3mqbj$1@dont-email.me> <v9idff$f9k4$1@dont-email.me> <v9iqln$hrs3$1@dont-email.me> <v9iro6$fql6$1@dont-email.me> <66bcf876$0$717$14726298@news.sunsite.dk> <66bcfbe3$0$717$14726298@news.sunsite.dk> <v9kske$uqhh$2@dont-email.me> <va04hl$2viks$2@dont-email.me> <66c397f6$0$716$14726298@news.sunsite.dk> <va226u$3ce14$1@dont-email.me> <va22l3$3cdrf$4@dont-email.me> <va26po$3d9f0$1@dont-email.me> <va3flv$3iue9$8@dont-email.me> <va4md4$3rubu$1@dont-email.me> <va5ao4$3v0jf$1@dont-email.me> <va8gki$joqn$1@dont-email.me> <va8h53$jkgq$1@dont-email.me> <20240823111404.00003c29@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 23 Aug 2024 15:02:37 +0200 (CEST) Injection-Info: dont-email.me; posting-host="cae1935b37e8e3671bba1001f109fc71"; logging-data="969837"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193PJylbttZ8Gy76ErH/P5CiPvq1Gk5wS4=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:U5lKsMzbiMT6mnSZMk4kul8sLJY= In-Reply-To: <20240823111404.00003c29@yahoo.com> Content-Language: en-US Bytes: 3790 On 8/23/2024 4:14 AM, Michael S wrote: > On Thu, 22 Aug 2024 19:21:07 -0400 > Arne Vajhøj <arne@vajhoej.dk> wrote: >> On 8/22/2024 7:12 PM, chrisq wrote: >>> On 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. > > Just admit that you was wrong I am often wrong so that is no big deal. > and that the best option in C is the same > as in many other languages - return the structure itself. Returning the struct itself result in a copy of the struct. The time to do the copy is probably insignificant though. Languages like (VMS) Pascal and (VMS) Basic do indeed return the record and make the copy. But newer languages (on VMS that would mostly be Java and other JVM languages but other platforms have more languages in this category) would dynamic allocate, return a reference/pointer and not worry about free because they use GC. I am not quite convinced yet. Arne