On 24/02/2019 17:42, The Natural Philosopher wrote:
> On 24/02/2019 15:18, Richard Heathfield wrote:
>> 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.
>>
>>
> Bet you the compiler output would be identical
>
> They are staggeringly cunning.
You may well be right. And yes, they are, aren't they?!
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|