TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: ALL
from: =?UTF-8?Q?BJ=C3=B6RN_LUND
date: 2019-02-25 20:50:00
subject: Re: C is not a low level

Den 2019-02-25 kl. 18:55, skrev Bart:
> On 24/02/2019 17:56, Bill Findlay wrote:
>> On 24 Feb 2019, Richard Heathfield wrote
>> (in article ):
>>
>>> On 24/02/2019 14:38, The Natural Philosopher wrote:
>>>> On 24/02/2019 13:09, Richard Heathfield wrote:
>>>>> If you take the trouble to ensure that you have enough space for your
>>>>> data, there's nothing wrong with using str.
>>>>
>>>> c=malloc(strlen(str)+1);
>>>> if(c)
>>>> strcpy (c,str);
>>>
>>> Indeed, although I'd cache the length rather than make the compiler find
>>> it twice:
>>>
>>> size_t len = strlen(str) + 1;
>>> c = malloc(len);
>>> if(c)
>>> memcpy(c, str, len);
>>>
>>> but it's a minor point.
>>
>> There is language in which you can write:
>>
>> copy : String := source;
>>
>> The compiler does all the work.
>> No need to use the heap.
>
> That depends on exactly what your line does. (Which actually is not that
> clear: is String the name of a type or of a variable?

>What's the 'copy:'
> for? I assume it copies one string to another, but if so, does it copy
> by value, or does it share the original string? Are the strings mutable?
> What is the maximum string length (since non-heap space is usually
> limited). etc.)

It pretty obvious.

'copy' is the name of a varible of type String.
String is mos likely an array of characters.
'Source' is also a name of a string varible.

So, 'copy' will become a string varible with a copy of the content of
'source', and it will have the sme size. and same boundaries.
(an array does not have to start with index zero)

strings are mutable as any array.
max size is dependend on heap-size.


>
>> The errors being discussed cannot happen, so no need for defensive
>> coding.
>> It is used when lives are at stake.
>> It runs, at least some, code faster than C.
>> It is available on the R Pi.
>>
>> Any guesses?
>
> No. Which one was it?


Ada


--
Björn

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.