Deutsch   English   Français   Italiano  
<vrl4g4$2lf61$1@paganini.bofh.team>

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

Path: ...!weretis.net!feeder8.news.weretis.net!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.lang.c
Subject: Re: Suggested method for returning a string from a C program?
Date: Sat, 22 Mar 2025 01:41:26 -0000 (UTC)
Organization: To protect and to server
Message-ID: <vrl4g4$2lf61$1@paganini.bofh.team>
References: <vrd77d$3nvtf$2@dont-email.me> <868qp1ra5f.fsf@linuxsc.com> <vrdhok$47cb$2@dont-email.me> <20250319115550.0000676f@yahoo.com> <vreuj1$1asii$4@dont-email.me> <vreve4$19klp$2@dont-email.me> <20250319201903.00005452@yahoo.com> <86r02roqdq.fsf@linuxsc.com> <vrh1br$35029$2@dont-email.me> <LRUCP.2$541.0@fx47.iad> <vrh71t$3be42$1@dont-email.me> <vrk8vm$2f4gc$1@paganini.bofh.team> <vrkulk$2k04q$1@dont-email.me>
Injection-Date: Sat, 22 Mar 2025 01:41:26 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="2800833"; posting-host="WwiNTD3IIceGeoS5hCc4+A.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.3
Bytes: 4144
Lines: 74

bart <bc@freeuk.com> wrote:
> On 21/03/2025 17:51, Waldek Hebisch wrote:
>> bart <bc@freeuk.com> wrote:
> 
>>> As defined by Unix/Linux, long is not portable between different
>>> Unix/Linux OSes if they run on a different architecture.
>> 
>> It portably between 32 and 64 bit machines gives word-sized
>> integer type.
> 
> Which was not its intention.

This was intention when 64-bit machines appeared.

> (Probably intptr_t or ssize_t is better for 
> that purpose, and will be portable between Windows and Linux.)

Those did not exist in 1991 and would be needed only for small
machines.  Except for Microsoft which decided to push its own,
different way.
 
>>> As defined by Microsoft, long is portable between Windows OSes even on
>>> different architectures.
>> 
>> It gives 'long' different meaning than it had previously.
> 
> 
> I explained the differences without necessarily saying one is better 
> than the other. Sometimes one is more more useful, sometimes the other.

AFAICS your main trouble with 'long' is inconsistency.  And the
inconsistency is due to Microsoft, as previously 'long' had
consitent definition on resonable machines: integer with max of
32 bits and word size, which simplified to word size on
"bigger" machines.

>> And to
>> that matters rather useless meaning, as already 'int' gives 32
>> bit integers on bigger machines.
> 
> Well, 'long' is also useless on 32-bit Linux machines as it is the same 
> size as 'int'.

Not always.  Motorola 68000 used 16-bit int.  That was because
original 68000 had 16-bit bus which made 16-bit integers faster.

> One 'con' for Linux' approach is when someone assumes 'long' is i32; 
> when they run code on 64 bits, it will either be wasteful, or it could 
> go badly wrong.

One 'con' of any assumption is that somebody can make a different
assumption.

> (I'm so glad I switched to all-64-bits in my own stuff, early last decade.
> 
> However lots of software has taken a long time to catch up. I acquired 
> an RPi 4 board 5 years ago with a view to doing 64-bit ARM development, 
> but most OSes were still 32 bits, and 64-bit ones immature. (You need a 
> 64-bit OS to easily develop and run 64-bit programs.)

I am not sure what was available for RPi 4.  But in 2019 I got 64-bit
chinese ARM board and it was well supported by 64-bit Linux (armbian).
Apparently Raspberry Pi foundation wanted to have the same OS on all
their boards (not only newest ones) so they delivered 32-bit OS for
some time after 64-bit board appeared.  IIUC normal Linux distributions
rather quickly got 64-bit ARM versions.

> Even now, 32-bit OSes are supplied by default. I finally got a solid 
> 64-bit OS for it last week. I just wondered what the point is of having 
> 64-bit hardware if people just run 32-bit stuff on it.)

See above.

-- 
                              Waldek Hebisch