Cloak
Cloak copied to clipboard
EAT / EXPAND undeclared
Hi I am getting error for EAT or EXPAND undeclared while using with WHEN(0) or WHEN(1)
It expands correctly for me:
#include "cloak.h"
WHEN(1)(true) // true
WHEN(0)(true) // nothing
Which outputs:
$ g++ -E -C when.h
# 3 "when.h" 2
true // true
// nothing
I see no undeclared message.
I am also having problems with EXPAND when used with the REPEAT macro:
#define DECL(i, _) stack[ i ] = 0; EVAL(REPEAT(3, DECL, ~))
generates the error messages: usb_dev.c: In function 'usb_dev_stack_reset': usb_dev.c:194: warning: implicit declaration of function 'EXPAND' usb_dev.c:194: error: syntax error before ';' token usb_dev.c:194: error: syntax error before ')' token
using -S -save-temps, I can see the from the intermediate file that EXPAND is being "painted blue": EXPAND (stack[ 0 ] = 0; stack[ 1 ] = 0;) stack[ 2 ] = 0;
so it only seems to expand the one time.
If I break up the REPEAT macro into multiple REPEAT macros so that I can use different EXPAND() macros (i.e. a unique WHEN + EXPAND for each and every REPEAT) , then my issues go away.
Of course, that defeats the whole purpose of the REPEAT macro. Any ideas? thanks!
The expand works if the REPEAT_INDIRECT() is OBSTRUCTED, but not if DEFER'd.
FYI: the cloak.h file has the correct code, as is the "C-Preprocessor-tricks,-tips,-and-idioms" wiki. However, the "Is-the-C-preprocessor-Turing-complete" has the DEFER macro.
from https://github.com/pfultz2/Cloak/wiki/Is-the-C-preprocessor-Turing-complete%3F:
#define REPEAT(count, macro, ...)
WHEN(count)
(
DEFER(REPEAT_INDIRECT) () \ <---- maybe this should be OBSTRUCT
(
DEC(count), macro, VA_ARGS
)
DEFER(macro)
(
DEC(count), VA_ARGS
)
)
#define REPEAT_INDIRECT() REPEAT
A note to y'all showing up late:
VA_ARGS is actually __VA_ARGS__
Github's Markdown formatting uses __FOO__
to indicate text which should be boldface.