From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20251 invoked by alias); 13 Dec 2013 20:47:31 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 20236 invoked by uid 89); 13 Dec 2013 20:47:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Received: from popelka.ms.mff.cuni.cz (HELO popelka.ms.mff.cuni.cz) (195.113.20.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2013 20:47:28 +0000 Received: from domone.kolej.mff.cuni.cz (popelka.ms.mff.cuni.cz [195.113.20.131]) by popelka.ms.mff.cuni.cz (Postfix) with ESMTPS id 039EF4FD2D; Fri, 13 Dec 2013 21:47:21 +0100 (CET) Received: by domone.kolej.mff.cuni.cz (Postfix, from userid 1000) id C86135F767; Fri, 13 Dec 2013 21:47:20 +0100 (CET) Date: Fri, 13 Dec 2013 20:47:00 -0000 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: Trevor Saunders Cc: gcc@gcc.gnu.org Subject: Re: replace do-while macros with static inline functions Message-ID: <20131213204720.GA16213@domone.podge> References: <20131213194223.GB31212@tsaunders-iceball.corp.tor1.mozilla.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20131213194223.GB31212@tsaunders-iceball.corp.tor1.mozilla.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-SW-Source: 2013-12/txt/msg00162.txt.bz2 On Fri, Dec 13, 2013 at 02:42:23PM -0500, Trevor Saunders wrote: > On Wed, Dec 11, 2013 at 08:33:03PM +0530, Prathamesh Kulkarni wrote: > > I was wondering if it was a good idea to replace do-while macros with > > static inline functions returning void, where appropriate ? > > By "where appropriate" I mean: > > a) call to macro contains no side-effects > > b) macro does not modify the arguments. > > c) macro does not use any preprocessor operators (like ##) > > d) macro does not get undefined or is conditionally defined. > > e) macro is not type independent (use inline template for these?) > > f) Any other case ? > > in general I'm infavor of replacing macros with unctions / constants / > templates etc. > > > Example: > > Consider C_EXPR_APPEND macro defined in c-tree.h: > > > > /* Append a new c_expr_t element to V. */ > > #define C_EXPR_APPEND(V, ELEM) \ > > do { \ > > c_expr_t __elem = (ELEM); \ > > vec_safe_push (V, __elem); \ > > } while (0) > > Its not my code, but that macro looks like a totally useless > abstruction, why not just inline the vec_safe_push() ? > Anyway if you inline macros you typically need to use always_inline. Quite often gcc makes mistake of not inlining these, a body looks much larger than actual inline expansion. Which is understandable as reason of macro could be avoiding a function call overhead.