__INCLUDE_LEVEL__

__INCLUDE_LEVEL__

Hello,

I tried to use the __INCLUDE_LEVEL__ preprocessor macro with the 9.1 c++ compiler for windows but it seems it's not supported, not in msvc either. Is there any way to get it to work?

Thanks

#include

using namespace std;

int main()
{
cout << __INCLUDE_LEVEL__ << endl;
}

error: identifier "__INCLUDE_LEVEL__" is undefined

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

As far as I can tell, __INCLUDE_LEVEL__ is a gcc extension(http://www.mhatt.aps.anl.gov/dohn/programming/gcc/cpp_3.htmlsection 3.7.2) and thus it's not likely that you'd find support for it on Windows, except with gcc.

That being said, it appears that icc doesn't have support for it even on Linux. I can file an issue on that, but I'm not sure that will help your case on Windows.

Just out of curiosity, how crucial is this to your code? And how are you using it?

Thanks!

Dale

Well, I am writing something with very repetitive code, so I thought of the following trick:

//-------file main.c----------

#include

int main()
{
#define REP_LIMIT 10
#define REP(BLAH)
printf("%d
", BLAH);
#include "rep.h"
return 0;
}

//--------file rep.h----------

#if __INCLUDE_LEVEL__ < REP_LIMIT
REP(__INCLUDE_LEVEL__)
#include "rep.h"
#endif

It's not very useful here, but together whth the ## preprocessor operator it could be used when dealing with multiple numbered variables (e.g. foo1, foo2, foo3 etc)

Roll your own. Suggestion:

-------file main.c----------

#include

int main()
{
#define REP_LEVEL 0
#define REP_LIMIT 10
#define REP(BLAH)
printf("%d
", BLAH);
#include "rep.h"
return 0;
}

//--------file rep.h----------
#define NEXT_REP_LEVEL (REP_LEVEL+1)
#define REP_LEVEL NEXT_REP_LEVEL
#if REP_LEVEL < REP_LIMIT
REP(REP_LEVEL)
#include "rep.h"
#endif

www.quickthreadprogramming.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today