Skip to content

Infinite loop in macro expansion #990

Description

@kant2002
#define EVAL0(...) __VA_ARGS__


#define MAP_END(...)
#define MAP_OUT

#define EMPTY() 
#define DEFER(id) id EMPTY()

#define MAP_NEXT(test, next)  next MAP_OUT

#define MAP0_UD_I(f, x, peek, ...) f(x) DEFER ( MAP_NEXT(peek, MAP1_UD_I) ) ( f, peek, __VA_ARGS__ ) 
#define MAP1_UD_I(f, x, peek, ...) f(x) DEFER ( MAP_NEXT(peek, MAP0_UD_I) ) ( f, peek, __VA_ARGS__ ) 

/**
 * Applies the function macro `f` to each of the remaining parameters, passes userdata as the second parameter to each invocation,
 * and the index of the invocation as the third parameter,
 * e.g. MAP_UD_I(f, x, a, b, c) evaluates to f(a, x, 0) f(b, x, 1) f(c, x, 2)
 */
#define MAP_UD_I(f, ...) EVAL0(MAP1_UD_I(f, 0, __VA_ARGS__, ()()(), ()()(), ()()(), 0))


/* Pass user-defined data and an index to each invocation */
#define PRINT_STREAM_I(x) printf ("d: d\n");
MAP_UD_I(PRINT_STREAM_I, 1, 2, 3, 4, 5)

Fails with stack overflow. Should fail with preprocessor error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions