Re: [gtk-list] g_assert() and consorts into {}?




> i'd like to see all the macros around g_assert () (return_if_fail...),
> to be enclosed by {}.

[ ... ]

> 
> any objections?

A good idea, but just {} is a bad idea - it can lead to warnings
(errors?) on some systems.

Here's how Perl does it:

/*
 * STMT_START { statements; } STMT_END;
 * can be used as a single statement, as in
 * if (x) STMT_START { ... } STMT_END; else ...
 *
 * Trying to select a version that gives no warnings...
 */
#if !(defined(STMT_START) && defined(STMT_END))
# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
#   define STMT_START	(void)(	/* gcc supports ``({ STATEMENTS; })'' */
#   define STMT_END	)
# else
   /* Now which other defined()s do we need here ??? */
#  if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
#   define STMT_START	if (1)
#   define STMT_END	else (void)0
#  else
#   define STMT_START	do
#   define STMT_END	while (0)
#  endif
# endif
#endif

We can probably just adopt this pretty much wholesale.
VOIDFLAGS is a #define which is true if 'void' is defined.
Since we don't care about pre-ANSI systems, we probably
can omit that. I'm not sure why SunOS (?) systems warn
about do { } while (0), but it doesn't cost much to
leave that in.

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]