Page 1 of 1

Finding the other end of #ifdef blocks

Posted: Sat Aug 25, 2012 9:47 am
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

Re: Finding the other end of #ifdef blocks

Posted: Mon Aug 27, 2012 10:48 am
by tod
Yes. See the image.
ifdefFolding.jpg
ifdefFolding.jpg (131.98 KiB) Viewed 5756 times

Re: Finding the other end of #ifdef blocks

Posted: Tue Aug 28, 2012 12:56 pm
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

Re: Finding the other end of #ifdef blocks

Posted: Wed Aug 29, 2012 10:58 am
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.

Re: Finding the other end of #ifdef blocks

Posted: Wed Sep 05, 2012 1:37 pm
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

Re: Finding the other end of #ifdef blocks

Posted: Wed Sep 05, 2012 2:34 pm
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.