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() ?
Trev
>
> It is called at two places in c-parser.c:
> 0 c-parser.c <global> 6140 C_EXPR_APPEND (cexpr_list, expr);
> 1 c-parser.c <global> 6145 C_EXPR_APPEND (cexpr_list, expr);
>
> Shall be replaced by:
>
> static inline void
> C_EXPR_APPEND( vec<c_expr_t, va_gc> * V, c_expr_t ELEM)
> {
> vec_safe_push(V, ELEM);
> }
>
> I will volunteer to do it, if it's accepted.
>
> Thanks and Regards,
> Prathamesh