From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92900 invoked by alias); 24 Feb 2020 12:31:08 -0000 Mailing-List: contact libc-help-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: libc-help-owner@sourceware.org Received: (qmail 92890 invoked by uid 89); 24 Feb 2020 12:31:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=didn, H*f:sk:87r1ykq, H*MI:sk:87r1ykq, H*i:sk:87r1ykq X-HELO: galex-713.eu Received: from portable.galex-713.eu (HELO galex-713.eu) (89.234.186.82) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 12:31:07 +0000 Received: from gal by galex-713.eu with local (Exim 4.92) (envelope-from ) id 1j6Ct1-0004ph-Jf; Mon, 24 Feb 2020 13:30:59 +0100 From: Alexandre =?ISO-8859-1?Q?Fran=E7ois?= Garreau To: Florian Weimer Cc: libc-help@sourceware.org Subject: Re: =?UTF-8?B?bWFsbG9j4oCZaW5n?= strcat Date: Mon, 24 Feb 2020 12:31:00 -0000 Message-ID: <1946575.pu6ZMUl000@galex-713.eu> In-Reply-To: <87r1ykqlp5.fsf@oldenburg2.str.redhat.com> References: <25950016.Ncol2qhMyO@galex-713.eu> <87r1ykqlp5.fsf@oldenburg2.str.redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00039.txt.bz2 Le lundi 24 f=C3=A9vrier 2020, 12:16:54 CET Florian Weimer a =C3=A9crit : > * Alexandre Fran=C3=A7ois Garreau: > > strcat needs a buffer already wide enough to contain concatenation of > > both strings, hence I deduce idiomatic use is to first > > malloc(strlen(str1) + strlen(str2) + 1)=E2=80=A6 > >=20 > > But then the usage must always be something like: > > #define strcat(a, b) strcat (strcpy (malloc (strlen(a) + strlen (b) + > > 1) a), b) > > (which, of course, requires further free())=E2=80=A6 > >=20 > > So is there already a function or macro which does that? if not so, > > why? > > One reason could be that before C11 (and C++11), it was difficult to > implement in a portable manner. You would have to use a variadic > function with a sentinel argument, and NULL as the most obvious (and > most portable) choice for the sentinel could silently truncate the > argument list if one of the arguments is specified incorrectly as NULL. I didn=E2=80=99t even talk about something variadic (my example macro has a= fixed=20 (2) valence)=E2=80=A6 but even so taking care about NULL to make variadicit= y to=20 works looks reasonable to me=E2=80=A6 But I=E2=80=99m curious, what did C11 change about that? And still, why wasn=E2=80=99t a macro such as the one I presented already=20 introduced?