Locally Declared Labels

Hi guys.

in the Locally Declared Labels section in "The Definitive Guide to GCC" book there is block of code:

#define SEARCH(array, target)
({
    __label__ found;
    typeof (target) _SEARCH_target = (target);
    typeof (*(array)) *_SEARCH_array = (array);
    int i, j;
    int value;
    for (i = 0; i < max; i++)
        for (j = 0; j < max; j++)
            if (_SEARCH_array[j] == _SEARCH_target)
                { value = i; goto found; }
        value = -1;
    found:
    value;
})

What the hell is the last line?

value;

The last line essentially makes the macro evaluate to value, almost like it being "return value;" if SEARCH() were a function.

1 Like