From owner-freebsd-questions@FreeBSD.ORG Sun May 4 11:34:06 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C55F51065670 for ; Sun, 4 May 2008 11:34:06 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from smtp-vbr11.xs4all.nl (smtp-vbr11.xs4all.nl [194.109.24.31]) by mx1.freebsd.org (Postfix) with ESMTP id 6C1C18FC28 for ; Sun, 4 May 2008 11:34:06 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from slackbox.xs4all.nl (slackbox.xs4all.nl [213.84.242.160]) by smtp-vbr11.xs4all.nl (8.13.8/8.13.8) with ESMTP id m44BY38X080492; Sun, 4 May 2008 13:34:04 +0200 (CEST) (envelope-from rsmith@xs4all.nl) Received: by slackbox.xs4all.nl (Postfix, from userid 1001) id D1437B844; Sun, 4 May 2008 13:34:03 +0200 (CEST) Date: Sun, 4 May 2008 13:34:03 +0200 From: Roland Smith To: Unga Message-ID: <20080504113403.GA51963@slackbox.xs4all.nl> Mail-Followup-To: Unga , freebsd-questions@freebsd.org References: <20080504075517.GA46776@slackbox.xs4all.nl> <404840.88790.qm@web57007.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FCuugMFkClbJLl1L" Content-Disposition: inline In-Reply-To: <404840.88790.qm@web57007.mail.re3.yahoo.com> X-GPG-Fingerprint: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 X-GPG-Key: http://www.xs4all.nl/~rsmith/pubkey.txt X-GPG-Notice: If this message is not signed, don't assume I sent it! User-Agent: Mutt/1.5.17 (2007-11-01) X-Virus-Scanned: by XS4ALL Virus Scanner Cc: freebsd-questions@freebsd.org Subject: Re: Variable arg function question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 May 2008 11:34:06 -0000 --FCuugMFkClbJLl1L Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, May 04, 2008 at 04:01:39AM -0700, Unga wrote: > > > Unfortunately va_arg() [stdarg(3)] does not return > > > NULL or any other suitable value after processing > > the > > > arg list, it just simply crashes once the arg list > > is > > > exhausted. > >=20 > > It is _your_ task to properly close the argument > > list. E.g. by supplying > > a NULL pointer as the last argument. > > =20 > Infact, I have implemented it in this way. I was > wondering if there is a better way. Not really within the bounds of the C language. > > > How do you guys implement variable arg function > > such > > > as f(str1, str2, str3, ..., strN)? > >=20 > > you could use the same format as main: int foo(int > > num, char **args) > >=20 >=20 > This is interesting. Who set the num? The compiler or > the user. If it is the user, its no better than above > NULL pointer method. >=20 > If this is possible, my problem is solved: > f(str1, str2, str3, ..., strN) is at compile time > expands to _f(int num, str1, str2, str3, ..., strN). >=20 > The num is set automatically by the compiler by > counting the args. >=20 > Is this possible? You could write a custom preporcessor that translates f calls into calls for _f. Roland --=20 R.F.Smith http://www.xs4all.nl/~rsmith/ [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated] pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725) --FCuugMFkClbJLl1L Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkgdnysACgkQEnfvsMMhpyVSYQCeLpjQ1+vqsghWUfPsywsc08QS UFkAnAgRp6QpYQKCYxzSzQDDJKcTDwx5 =so2d -----END PGP SIGNATURE----- --FCuugMFkClbJLl1L--