Re: avoiding strdup()

Liste des GroupesRevenir à cl c  
Sujet : Re: avoiding strdup()
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.c
Date : 13. Mar 2024, 00:44:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <usqlsu$hqqv$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla Thunderbird
On 12/03/2024 15:55, Scott Lurndal wrote:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
On 11/03/2024 17:00, Scott Lurndal wrote:
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
On 10/03/2024 18:47, Scott Lurndal wrote:
Kaz Kylheku <433-929-6894@kylheku.com> writes:
On 2024-03-10, Michael S <already5chosen@yahoo.com> wrote:
On Sat, 09 Mar 2024 16:37:19 -0800
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
strdup() and strndup() are being added to the C23 standard.
>
>
What is justification?
>
strdup is required by POSIX already and thus widely implemented.
Many programmers who are not into standards already assume it's in C.
>
For decades, portable programs have been doing things like this:
>
#if HAVE_STRDUP
#define xstrdup(s) strdup(s)
#else
char *xstrdup(const char *); // own definition
#endif
>
What strdup() can do better, for any chosen value of better, than
strlen()+malloc()+memcpy() ?
>
Not take up space in every application for a common library routine.
>
It's a form of lazy programming.  I've seen a lot of open source
code that uses strdup without checking for failure and frequently
"forgetting" to free the result.
>
And it is probably more likely that machine with many gigabytes of RAM
Actually, your assumptions that:
    1) strdup is the only allocation function used by an application
    2) all strings are "short"
are both flawed.
>
The bank has many billions. But there is a banking crisis on and it is
about to fail. And someone, somewhere, will be that man who tries to
withdraw some money and is told "no". But how likely is that man to be
you with your 20 pounds at the cashpoint? How likely is it to be
another bank making a cash call for a 100 million or so?
>
If I withdraw 20 pounds from my bank, I'll bet you that 20 pounds that
the bank still checks whether it has the money.
 And as for "how likely it is that the bank will not be able
to honor withdrawal requests", I refer Malcolm to 1931.
    "In 1930, 1,352 banks held more than $853 million in
    deposits; in 1931, one year later, 2,294 banks failed
    with nearly $1.7 billion in deposits."
 
So 2,294 Americans in 1932 had the experience "you want to withdraw cash? OK, here we go, oh sorry, that just took us over the edge and the bank is now closed". Everyone else, either "here's your money", or "sorry, the bank has now closed, no more withdrawal requests".
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Date Sujet#  Auteur
7 Mar 24 * Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"51Ben
9 Mar 24 `* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"50Blue-Maned_Hawk
9 Mar 24  +* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"5Keith Thompson
9 Mar 24  i`* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"4Blue-Maned_Hawk
9 Mar 24  i `* Re: [OT] UTF-8 sig.3vallor
10 Mar 24  i  `* Re: [OT] UTF-8 sig.2Blue-Maned_Hawk
21 Mar 24  i   `- Re: [OT] UTF-8 sig.1Anton Shepelev
9 Mar 24  `* Re: [OT] UTF-8 sig.44Ben
9 Mar 24   +* Re: [OT] UTF-8 sig.3Richard Harnden
10 Mar 24   i`* Re: [OT] UTF-8 sig.2Ben Bacarisse
10 Mar 24   i `- Re: [OT] UTF-8 sig.1Richard Harnden
9 Mar 24   +* Re: [OT] UTF-8 sig.7Blue-Maned_Hawk
9 Mar 24   i`* Re: [OT] UTF-8 sig.6Richard Harnden
10 Mar 24   i +- Re: [OT] UTF-8 sig.1Blue-Maned_Hawk
10 Mar 24   i `* Re: [OT] UTF-8 sig.4Ben Bacarisse
10 Mar 24   i  `* Re: [OT] UTF-8 sig.3Michael S
10 Mar 24   i   +- Re: [OT] UTF-8 sig.1Blue-Maned_Hawk
10 Mar 24   i   `- Re: [OT] UTF-8 sig.1Kaz Kylheku
9 Mar 24   `* avoiding strdup() (was: Re: [OT] UTF-8 sig.)33vallor
9 Mar 24    +- Re: avoiding strdup()1Spiros Bousbouras
10 Mar 24    +* Re: avoiding strdup()30Keith Thompson
10 Mar 24    i`* Re: avoiding strdup()29Michael S
10 Mar 24    i +- Re: avoiding strdup()1Blue-Maned_Hawk
10 Mar 24    i `* Re: avoiding strdup()27Kaz Kylheku
10 Mar 24    i  +- Re: avoiding strdup()1Richard Harnden
11 Mar 24    i  +* Re: avoiding strdup()22Malcolm McLean
11 Mar 24    i  i+* Re: avoiding strdup()10Michael S
11 Mar 24    i  ii+* Re: avoiding strdup()6Keith Thompson
11 Mar 24    i  iii+* Re: avoiding strdup()2Kaz Kylheku
11 Mar 24    i  iiii`- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  iii+- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  iii`* Re: avoiding strdup()2Spiros Bousbouras
11 Mar 24    i  iii `- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  ii`* Re: avoiding strdup()3Michael S
11 Mar 24    i  ii +- Re: avoiding strdup()1Michael S
11 Mar 24    i  ii `- Re: avoiding strdup()1Spiros Bousbouras
11 Mar 24    i  i+* Re: avoiding strdup()3Kaz Kylheku
11 Mar 24    i  ii`* Re: avoiding strdup()2Richard Kettlewell
11 Mar 24    i  ii `- Re: avoiding strdup()1Keith Thompson
12 Mar 24    i  i`* Re: avoiding strdup()8Malcolm McLean
12 Mar 24    i  i `* Re: avoiding strdup()7Keith Thompson
12 Mar 24    i  i  +* Re: avoiding strdup()3Malcolm McLean
13 Mar 24    i  i  i`* Re: avoiding strdup()2Keith Thompson
13 Mar 24    i  i  i `- Re: avoiding strdup()1Malcolm McLean
13 Mar 24    i  i  `* Re: avoiding strdup()3Malcolm McLean
13 Mar 24    i  i   `* Re: avoiding strdup()2James Kuyper
13 Mar 24    i  i    `- Re: avoiding strdup()1David Brown
29 Apr 24    i  `* Re: avoiding strdup()3Lawrence D'Oliveiro
29 Apr 24    i   `* Re: avoiding strdup()2i
1 May 24    i    `- Re: avoiding strdup()1steve
10 Mar 24    `- Re: avoiding strdup()1Richard Harnden

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal