Finding the other end of #ifdef blocks

Topics for the Eclipse Environment
Post Reply
barttech
Posts: 135
Joined: Fri Feb 20, 2009 12:59 pm

Finding the other end of #ifdef blocks

Post by barttech »

I have Eclipse set up to grey out areas inside an #ifdef or #ifndef that are not complied, and I've commented my #endif s to make it clearer where my blocks are, but somewhere I've got an extra unmatched #ifdef that I cannot find.
Eclipse will highlight a code block if you double-click to the right of the { or }. Is there a way to get it to do similar thing with #ifdef blocks?
Sam
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Finding the other end of #ifdef blocks

Post by tod »

Yes. See the image.
ifdefFolding.jpg
ifdefFolding.jpg (131.98 KiB) Viewed 6152 times
barttech
Posts: 135
Joined: Fri Feb 20, 2009 12:59 pm

Re: Finding the other end of #ifdef blocks

Post by barttech »

Thanks Tod,
Another useful feature I didn't know about. Seems you can also do Ctrl-<Numpad/> to toggle it on and off.
I actually wanted to be able to have the block highlighted, not collapsed, but I think this would have helped me find my mis-matched #ifdef blocks as well.
Sam
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Finding the other end of #ifdef blocks

Post by tod »

I don't know of a way to highlight the folded code. I discovered this folding feature when trying to emulate Visual Studio's region folding, I documented the process for code region folding in Eclipse. The short version is to just combine the trick I showed you here with #if(1)/#endif. Of course it's better to keep your classes short enough that you don't need regions at all, but for some dispatch and mediator classes that can be problematic.
barttech
Posts: 135
Joined: Fri Feb 20, 2009 12:59 pm

Re: Finding the other end of #ifdef blocks

Post by barttech »

I just stumbled on what I was looking for.
If you have code folding on but expand the section of #ifdef of interest, and you hover over the circled -, it will draw a line to the corresponding #endif. Handy when you've grabbed too many lines in a cut and paste and you end up with an "unbalanced #endif".
Sam
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Finding the other end of #ifdef blocks

Post by tod »

If you use the Outline window (and why wouldn't you?) you'll also notice that #if and #ifdef affect that view too. Items hidden are shown with a different icon and there's an option to completely hide the inactive items. That could provide some quick forensics when looking at a large classes.
Post Reply