Path: ...!feeds.phibee-telecom.net!3.eu.feeder.erje.net!feeder.erje.net!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Date: Fri, 23 Aug 2024 13:03:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: New VSI post on Youtube Newsgroups: comp.os.vms References: <66bcf876$0$717$14726298@news.sunsite.dk> <66bcfbe3$0$717$14726298@news.sunsite.dk> <66c397f6$0$716$14726298@news.sunsite.dk> <20240823111404.00003c29@yahoo.com> Content-Language: en-US From: =?UTF-8?Q?Arne_Vajh=C3=B8j?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Lines: 107 Message-ID: <66c8c0f0$0$705$14726298@news.sunsite.dk> Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 8854e066.news.sunsite.dk X-Trace: 1724432625 news.sunsite.dk 705 arne@vajhoej.dk/68.14.27.188:55798 X-Complaints-To: staff@sunsite.dk Bytes: 3254 On 8/23/2024 9:02 AM, Arne Vajhøj wrote: > On 8/23/2024 4:14 AM, Michael S wrote: >>                     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. > I am not quite convinced yet. It seems like one frequently provided reason for using pointer is ABI compatibility. I don't know about that. It is not that easy to create the problem. But it is possible: $ type i.h struct data { int a; int b; #ifdef NEWVERSION int c; #endif }; $ type s1.c #include "i.h" struct data get() { struct data res; res.a = 123; res.b = 456; #ifdef NEWVERSION res.c = 0x7FFFFFFF; #endif return res; } $ type m1.c #include #include "i.h" struct data get(); int main() { struct data res = get(); printf("%d %d\n", res.a, res.b); return 0; } $ type s2.c #include #include "i.h" struct data *get() { struct data *res = malloc(sizeof(struct data)); res->a = 123; res->b = 456; #ifdef NEWVERSION res->c = 0x7FFFFFFF; #endif return res; } $ type m2.c #include #include #include "i.h" struct data *get(); int main() { struct data *res = get(); printf("%d %d\n", res->a, res->b); free(res); return 0; } $ cc s1 $ cc m1 $ link m1 + s1 $ run m1 123 456 $ cc/define="NEWVERSION" s1 $ link m1 + s1 $ run m1 99108 0 $ cc s2 $ cc m2 $ link m2 + s2 $ run m2 123 456 $ cc/define="NEWVERSION" s2 $ link m2 + s2 $ run m2 123 456 Arne