2.1.7. Macro Expansion

Within the code of Zlib, infback9.c has few macros. Let’s see an example of NEEDBITS.

#define NEEDBITS(n)                         \
    do {                                    \
        while (bits < (unsigned)(n))        \
            PULLBYTE();                     \
    } while (0)

But. the macro NEEDBITS depends on PULLBYTE

#define PULLBYTE()                                \
    do {                                          \
        PULL();                                   \
        have--;                                   \
        hold += (unsigned long)(*next++) << bits; \
        bits += 8;                                \
    } while (0)

The dependencies continue.

#define PULL()                              \
    do {                                    \
        if (have == 0) {                    \
            have = in(in_desc, &next);      \
            if (have == 0) {                \
                next = Z_NULL;              \
                ret = Z_BUF_ERROR;          \
                goto inf_leave;             \
            }                               \
        }                                   \
    } while (0)

#define Z_NULL  0

#define Z_BUF_ERROR    (-5)

Now. What does NEEDBITS(3) expand to?

Just hover cursor on the Macro. See the full expansion of the Macro.

Full expansion of the NEEDBITS macro

If this is an information overflow, we can also see the expansion Step-by-Step. Press F2.

Step by Step expansion of Macro in Eclipse Editor

Press Right Arrow or Alt + Right to see step by step expansion.

Step 1/5:

Step by Step expansion of Macro in Eclipse Editor

Step 2/5:

Step by Step expansion of Macro in Eclipse Editor

Step 3/5:

../../../_images/e-macro-nb-exp-3-5.png

And so on...

Tip: Press left/right arrow to go to previous/next page.