Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EAT / EXPAND undeclared #8

Open
kanni1303 opened this issue Aug 21, 2018 · 4 comments
Open

EAT / EXPAND undeclared #8

kanni1303 opened this issue Aug 21, 2018 · 4 comments

Comments

@kanni1303
Copy link

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

@pfultz2
Copy link
Owner

pfultz2 commented Aug 21, 2018

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.

@austen42
Copy link

austen42 commented Mar 1, 2019

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
Copy link

austen42 commented Mar 1, 2019

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

@aakropotkin
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants