[Python-Dev] if/else and macros (was: CVS: python/dist/src/Objects unicodeobject.c,2.48,2.49)

Greg Stein gstein@lyra.org
Sun, 16 Jul 2000 15:37:36 -0700


On Mon, Jul 17, 2000 at 12:01:48AM +0200, M.-A. Lemburg wrote:
> Greg Stein wrote:
>...
> > ! #define UTF8_ERROR(details) \
> > !   if (1) {                                                  \
> > !       if (utf8_decoding_error(&s, &p, errors, (details)))   \
> > !           goto onError;                                     \
> > !       continue;                                             \
> > !   } else
> 
> Greg, this doesn't work... UTF8_ERROR is used in if-clauses
> and the above may alter the else-branches in subtle ways which
> are just as hard to detect as the original bug. The goto may
> not be the greatest in style, but it doesn't have the above
> caveats.

Nope. It *does* work. Note the "else" on the end there. That creates the
proper binding.

All uses of the UTF8_ERROR() macro have a semicolon after them (like any
normal statement does(!)). This expands the macro to:

    if (1) {
       ...
    } else
       ;       /* this is the semicolon I referred to */

Therefore, it creates a complete if/else statement, and any surrounding
if/else statements will bind as expected.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/