[dpdk-dev] [PATCH 01/11] ip_pipeline: add parsing for config files with new syntax

Dumitrescu, Cristian cristian.dumitrescu at intel.com
Thu Jun 4 19:29:13 CEST 2015



> -----Original Message-----
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Stephen
> Hemminger
> Sent: Monday, June 1, 2015 2:34 PM
> To: Gajdzica, MaciejX T
> Cc: dev at dpdk.org
> Subject: Re: [dpdk-dev] [PATCH 01/11] ip_pipeline: add parsing for config
> files with new syntax
> 
> On Fri, 29 May 2015 17:43:08 +0200
> Maciej Gajdzica <maciejx.t.gajdzica at intel.com> wrote:
> 
> > +/**
> > + * Find object of name *name* in *obj_array* which is constant size array
> 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 = RTE_DIM(obj_array);               \
> > +                                                                \
> > +	for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {         \
> > +		if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
> > +			continue;                                           \
> > +			                                                    \
> > +		if (strcmp(key, (obj_array)[obj_idx].name) == 0)        \
> > +			break;                                              \
> > +	}                                                           \
> > +	obj_idx < obj_count ? obj_idx : -ENOENT;                    \
> > +})
> 
> Converting all the functions to macro's is a step backwards in several ways.
>  * macro's are hard to support
>  * macro's lead to lots of programming errors
>  * macro's look ugly
> 
> 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 quasi-identical function per each object type, which would lead to unnecessary code duplication.

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

All the DPDK sample applications are written in C, so this is the main reason 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 application.




More information about the dev mailing list