From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <cristian.dumitrescu@intel.com>
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id 6220AC31C
 for <dev@dpdk.org>; Thu,  4 Jun 2015 19:29:17 +0200 (CEST)
Received: from fmsmga001.fm.intel.com ([10.253.24.23])
 by orsmga101.jf.intel.com with ESMTP; 04 Jun 2015 10:29:16 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.13,553,1427785200"; d="scan'208";a="720868593"
Received: from irsmsx106.ger.corp.intel.com ([163.33.3.31])
 by fmsmga001.fm.intel.com with ESMTP; 04 Jun 2015 10:29:15 -0700
Received: from irsmsx108.ger.corp.intel.com ([169.254.11.59]) by
 IRSMSX106.ger.corp.intel.com ([169.254.8.189]) with mapi id 14.03.0224.002;
 Thu, 4 Jun 2015 18:29:15 +0100
From: "Dumitrescu, Cristian" <cristian.dumitrescu@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>, "Gajdzica, MaciejX T"
 <maciejx.t.gajdzica@intel.com>
Thread-Topic: [dpdk-dev] [PATCH 01/11] ip_pipeline: add parsing for config
 files with new syntax
Thread-Index: AQHQnG+0/twVAzLa4Uy4ReKE0uHlIZ2cnOrQ
Date: Thu, 4 Jun 2015 17:29:13 +0000
Message-ID: <3EB4FA525960D640B5BDFFD6A3D89126323714C7@IRSMSX108.ger.corp.intel.com>
References: <1432914198-11812-1-git-send-email-maciejx.t.gajdzica@intel.com>
 <1432914198-11812-2-git-send-email-maciejx.t.gajdzica@intel.com>
 <20150601063412.5805c879@urahara>
In-Reply-To: <20150601063412.5805c879@urahara>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [163.33.239.182]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 01/11] ip_pipeline: add parsing for config
 files with new syntax
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Jun 2015 17:29:17 -0000



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen
> Hemminger
> Sent: Monday, June 1, 2015 2:34 PM
> To: Gajdzica, MaciejX T
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH 01/11] ip_pipeline: add parsing for config
> files with new syntax
>=20
> On Fri, 29 May 2015 17:43:08 +0200
> Maciej Gajdzica <maciejx.t.gajdzica@intel.com> wrote:
>=20
> > +/**
> > + * Find object of name *name* in *obj_array* which is constant size ar=
ray
> of
> > + * elements that have field *name*.
> > + *
> > + * @param obj_array
> > + *  Constant size array
> > + * @param name
> > + *  name of object to find.
> > + * @return
> > + *  Pointer to object in *obj_array* or NULL if not found.
> > + */
> > +#define APP_PARAM_FIND(obj_array, key)                          \
> > +({                                                              \
> > +	ssize_t obj_idx;                                            \
> > +	const ssize_t obj_count =3D RTE_DIM(obj_array);               \
> > +                                                                \
> > +	for (obj_idx =3D 0; obj_idx < obj_count; obj_idx++) {         \
> > +		if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
> > +			continue;                                           \
> > +			                                                    \
> > +		if (strcmp(key, (obj_array)[obj_idx].name) =3D=3D 0)        \
> > +			break;                                              \
> > +	}                                                           \
> > +	obj_idx < obj_count ? obj_idx : -ENOENT;                    \
> > +})
>=20
> Converting all the functions to macro's is a step backwards in several wa=
ys.
>  * macro's are hard to support
>  * macro's lead to lots of programming errors
>  * macro's look ugly
>=20
> Why not use real functions, or make the example into C++ if you have
> to do generic programming.

We are using macros here only because C language does not offer us a better=
 choice (i.e. support for templates). The alternative would be to write a q=
uasi-identical function per each object type, which would lead to unnecessa=
ry code duplication.

We did our best to keep the number of macros small and to implement each ma=
cro as straightforward as possible.

All the DPDK sample applications are written in C, so this is the main reas=
on we want to keep this application as C code. As people expect C code from=
 DPDK sample apps, it is easier for people to reuse parts of this applicati=
on.