From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH 01/11] ip_pipeline: add parsing for config files with new syntax Date: Mon, 1 Jun 2015 06:34:12 -0700 Message-ID: <20150601063412.5805c879@urahara> References: <1432914198-11812-1-git-send-email-maciejx.t.gajdzica@intel.com> <1432914198-11812-2-git-send-email-maciejx.t.gajdzica@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org To: Maciej Gajdzica Return-path: Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by dpdk.org (Postfix) with ESMTP id D0BEC58C3 for ; Mon, 1 Jun 2015 15:34:10 +0200 (CEST) Received: by padjw17 with SMTP id jw17so37261092pad.2 for ; Mon, 01 Jun 2015 06:34:10 -0700 (PDT) In-Reply-To: <1432914198-11812-2-git-send-email-maciejx.t.gajdzica@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 29 May 2015 17:43:08 +0200 Maciej Gajdzica 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.