Date: Sun, 4 May 2008 17:47:34 +0200 From: Roland Smith <rsmith@xs4all.nl> To: Unga <unga888@yahoo.com> Cc: Patrick Clochesy <pcloches@gmail.com>, freebsd-questions@freebsd.org Subject: Re: Variable arg function question Message-ID: <20080504154734.GA98310@slackbox.xs4all.nl> In-Reply-To: <630200.71551.qm@web57011.mail.re3.yahoo.com> References: <20080504144532.GA56965@slackbox.xs4all.nl> <630200.71551.qm@web57011.mail.re3.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, May 04, 2008 at 08:34:30AM -0700, Unga wrote: >=20 > --- Roland Smith <rsmith@xs4all.nl> wrote: >=20 > > On Sun, May 04, 2008 at 07:02:36AM -0700, Patrick > > Clochesy wrote: > > > What about using a macro (...) in front of the > > function to csll it which=20 > > > passes __VARARGS__, NULL to ensure there is always > > a trailing NULL? I think=20 > > > this would at least work in GCC... Can' test on my > > phone though. > >=20 > > That's a good idea. If one uses __VA_ARGS__ instead > > of __VARARGS__, it > > should work with any C99 compliant compiler, > > including gcc. > I gave it a try, but I cannot get it to work: > (As per above wikipedia example) >=20 > void realdprintf (char const *file, int line, char > const *fmt, ...);=20 > #define dprintf(...) realdprintf(__FILE__, __LINE__, > __VA_ARGS__) >=20 > To solve my problem, I must be able to indicate the > end of the arg list, may be by a empty string (""), > but GNU C compiler does not allow to specify anything > after the ... . Try something like what Patrick suggested: #define f(...) _f(__VA_ARGS__,NULL) 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) --HcAYCG3uE/tztfnV Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkgd2pYACgkQEnfvsMMhpyVRkwCfcybIIXDxyps4+w2IRwMXIXBJ tcYAn18HLVbznyHhtWSrOKWLNIfXlXyX =hYUe -----END PGP SIGNATURE----- --HcAYCG3uE/tztfnV--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080504154734.GA98310>