1

I have header base.h containing

#ifndef GUARD_H
#define GUARD_H

<my code>

#endif

Eclipse CDT is graying out everything below #ifndef GUARD_H. This would be correct if GUARD_H were defined, but it is not. Actually, the only place where it is defined across my system is the following line, precisely as intended for an include guard. So, I cannot see why this happens.

Moreover, among the hundreds of headers I used under Eclipse CDT in my life, and in particular under the present project, this is the first time I see such a thing.

Why does this happen? How can I fix this?

Using Eclipse IDE for C/C++ Developers, Version: 2018-09 (4.9.0), Build id: 20180917-1800 under Win 10.

  • 1
    It's hard to say without knowing more about your project setup. Usually this happens when the header file is parsed in multiple contexts (macro environments) and for some reason CDT opens a wrong / undesirable one. Often, it's solved by using a more accurate way of specifying includes (e.g. using the Build Output Parser which assigns each file its own settings, rather than a global set of includes). Sometimes, adding the header to `Preferences -> C/C++ -> Indexer -> Index all variants of specific headers` helps. ("Index all header variants" can also help but at a possible performance cost.) – HighCommander4 Oct 31 '19 at 01:17
  • @HighCommander4 - In "parsed in multiple contexts (macro environments)", I wouldn't know what a macro environment is. Would you care for clarifying? And perhaps pointing to some documentation on that specifics? Please also see edited OP. – sancho.s ReinstateMonicaCellio Oct 31 '19 at 04:08
  • @HighCommander4 - I also checked Project Properties -> C/C++ General -> Preprocessor Include Paths -> Providers -> CDT GCC Build Output Parser (I guess you were referring to this), but so far I do not understand its purpose, subsettings, and how it works. – sancho.s ReinstateMonicaCellio Oct 31 '19 at 04:20
  • @HighCommander4 - I tried adding the header to `Preferences -> C/C++ -> Indexer -> Index all variants of specific headers`. It worked, now all of the inner code is not grayed out anymore. But now `GUARD_H` in `#ifndef GUARD_H` is grayed out. I wouldn't know what this means, and it is the first time I see it. PS: Neither [this](https://wiki.eclipse.org/CDT/User/NewIn83#Preferences_for_header_variants) or [this](https://stackoverflow.com/questions/27217857/eclipse-luna-cdt-what-is-a-header-variant) helped clarifying for me what a header variant is. – sancho.s ReinstateMonicaCellio Oct 31 '19 at 04:57
  • @HighCommander4 - You could post your comment as an answer. It actually helped me a lot, so it could help others as well. – sancho.s ReinstateMonicaCellio Jan 12 '21 at 15:30

2 Answers2

0

As per this comment, adding affected headers to Preferences -> C/C++ -> Indexer -> Index all variants of specific headers (separated by semicolon) helps. "Index all header variants" can also help but at a possible performance cost.

I found it sometimes works. Sometimes it doesn't, but it starts working at a later time while I am coding or navigating, without any apparent specific action on my side. Also the opposite, sometimes code becomes greyed out, without any apparent specific action on my side.

0

Found this serendipitously. Changing affected headers to something like

#ifndef GUARD_H
#define GUARD_H

<my code>

#endif // GUARD_H   <-- Modification

did the job in a few cases I tried.