Macro not declared in this scope
Posted
by
NmdMystery
on Stack Overflow
See other posts from Stack Overflow
or by NmdMystery
Published on 2013-10-24T03:49:39Z
Indexed on
2013/10/24
3:53 UTC
Read the original article
Hit count: 132
I'm using a preprocessor #define macro to count the number of functions in a header file:
#define __INDEX -1
//First group of functions
void func1(void);
#define __FUNC1_INDEX __INDEX + 1
void func2(void);
#define __FUNC2_INDEX __FUNC1_INDEX + 1
#undef __INDEX
#define __INDEX __FUNC2_INDEX
//Second group of functions
void func3(void);
#define __FUNC3_INDEX __INDEX + 1
void func4(void);
#define __FUNC4_INDEX __FUNC3_INDEX + 1
#undef __INDEX
#define __INDEX __FUNC4_INDEX
//Third group of functions
void func5(void);
#define __FUNC5_INDEX __INDEX + 1
void func6(void);
#define __FUNC6_INDEX __FUNC5_INDEX + 1
#undef __INDEX
#define __INDEX __FUNC6_INDEX
#define __NUM_FUNCTIONS __INDEX + 1
The preprocessor gets through the first two sets of functions just fine, but when it reaches the line:
#define __FUNC5_INDEX __INDEX + 1
I get a "not defined in this scope" error for __INDEX. What makes this really confusing is the fact that the same exact thing is done [successfully] in the second group of functions; __FUNC3_INDEX takes on the value of __INDEX + 1. There's no typos anywhere, as far as I can tell... what's the problem?
I'm using g++ 4.8.
© Stack Overflow or respective owner