Cloak icon indicating copy to clipboard operation
Cloak copied to clipboard

EAT / EXPAND undeclared

Open kanni1303 opened this issue 5 years ago • 4 comments

Hi I am getting error for EAT or EXPAND undeclared while using with WHEN(0) or WHEN(1)

kanni1303 avatar Aug 21 '18 16:08 kanni1303

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.

pfultz2 avatar Aug 21 '18 16:08 pfultz2

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!

austen42 avatar Mar 01 '19 07:03 austen42

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

austen42 avatar Mar 01 '19 17:03 austen42

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.

aakropotkin avatar May 05 '19 00:05 aakropotkin