On 24 Feb 2019, The Natural Philosopher wrote
(in article ):
> 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.
>
> Instead it uses some sort of memory management that may do garbage
> collection at any time not under your control
No, it does not. You have jumped to an unwarranted conclusion.
> > The errors being discussed cannot happen, so no need for defensive coding.
> > It is used when lives are at stake.
>
> It puts lives at risk
Bollocks.
> > It runs, at least some, code faster than C. It is available on the R Pi.
> > Any guesses?
> could be any one of a dozen me too languages.
Name one.
--
Bill Findlay
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|