Deutsch   English   Français   Italiano  
<66c8c0f0$0$705$14726298@news.sunsite.dk>

View for Bookmarking (what is this?)
Look up another Usenet article

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: <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> <vaa19c$tj3d$1@dont-email.me>
Content-Language: en-US
From: =?UTF-8?Q?Arne_Vajh=C3=B8j?= <arne@vajhoej.dk>
In-Reply-To: <vaa19c$tj3d$1@dont-email.me>
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 <stdio.h>

#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 <stdlib.h>

#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 <stdio.h>
#include <stdlib.h>

#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