Author |
Topic |
|
msew
Ketchup Master
94 Posts |
Posted - Feb 26 2004 : 03:58:17 AM
|
so you have the wonderful redundent include guards.
Now you want to alphabatize them. Pain ensues. Can you Visual Assist have a pattern that looks for this type of structure and then sorts by the first line?
#ifndef _NAMESPACE_CLASSNAMEARRRR_H_ #include "ClassNameArrr.h" #endif
|
|
LarryLeonard
Tomato Guru
USA
1041 Posts |
Posted - Feb 26 2004 : 09:26:39 AM
|
I've actually been thinking about whether I need guard defines anymore; I doubt I'll ever port anything I've ever written (MFC stuff, anyway) to a compiler that doesn't support #pragma once. Just for my own curiosity, when are you finding that #pragma once won't work, and you need guard defines?
|
|
|
willdean
Tomato Guru
134 Posts |
Posted - Feb 26 2004 : 12:11:43 PM
|
To msew:
I don't think I understand what you're asking for here - include guards are normally *inside* header files, not around the #include itself.
If you put them inside a header file, you only ever have one at once.
Like Larry says, if you're writing inherently non-portable stuff (like MFC) code, then '#pragma once' is faster and easier.
Much of my code needs to compile on multiple compilers, most of which don't support #pragma once, so I still add them manually - but I still don't understand the 'alphabatize' [sic] bit.
I would like a feature in VA which autmatically added the subject of the #if as a comment to after the #endif - so that you get:
#if wibble
#endif // wibble
for a bit less typing...
|
|
|
LarryLeonard
Tomato Guru
USA
1041 Posts |
Posted - Feb 26 2004 : 12:29:56 PM
|
Well, I mean, sometimes you have to do what msew wants if you're trying to guard someone else's header file, and you don't want to modify it... but from the name ClassNameArrr, I assumed it was one he authored himself.
The alphabetizing thing he wants I think would work like this. Say you have 35 'wibble'-type #ifndef blocks, for files ranging from '_AARDVARK_WIBBLE' to "_ZEBRA_WIBBLE', but not in any order. He wants to be able to sort those blocks. That would be pretty hard to generalize, I'm thinking.
Also, I agree that it would be a nice feature for VA to "autmatically" add #endif comments. (The urge to type [sic] is almost overwhelming - instead I'll point you to some freeware: www.iespell.com I love it.)
|
|
|
Stephen
Tomato Guru
United Kingdom
781 Posts |
Posted - Feb 26 2004 : 1:35:07 PM
|
This suggestion seems to be very specific to msew's particular case. |
Stephen Turner ClickTracks http://www.clicktracks.com/ Winner: ClickZ's Best Web Analytics Tool 2003 & 2004
|
|
|
willdean
Tomato Guru
134 Posts |
Posted - Feb 26 2004 : 5:25:20 PM
|
Thanks Larry, but I don't use IE!
No typo/spelling flame is ever complete without a few of its own...
|
|
|
Cezariusz
Tomato Guru
Poland
244 Posts |
Posted - Feb 27 2004 : 05:30:01 AM
|
willdean: there are also spelling plugins available for Firefox |
Cezariusz Marek https://midicat.net/ |
|
|
feline
Whole Tomato Software
United Kingdom
19015 Posts |
Posted - Mar 02 2004 : 11:48:39 AM
|
quote: Originally posted by msew
so you have the wonderful redundent include guards.
if you have quite a few of these to sort, could you:
use a VS macro to join the three lines for each include into one with the pieces separated by spaces.
now you have a set of lines that VAX should sort correctly
now use a second VS macro to split the lines again. since they are space separated a given number of ctrl+left arrow presses should get you to the right place for the line breaks.
something of a fuss, but i have done similar things with macros in vim on many occasions, and it is a real time saver. worth considering if this is a common problem and the VS macros are up to the job. |
zen is the art of being at one with the two'ness |
|
|
asmout
Ketchup Master
58 Posts |
Posted - Mar 08 2004 : 7:42:10 PM
|
Willdean,
I think one point of the syntax:
#ifndef INCLUDED_blah #include "blah.h" #endif
is that the compiler does not need to open the file "blah.h" to discover that it is not needed. This can (marginally) speed up compilation times (though it is a pain to type). Of course, you must still put the guard _inside_ blah.h as well:
#ifndef INCLUDED_blah #define INCLUDED_blah
< your code here >
#endif // INCLUDED_blah
Do you know if "#pragma once" has the same file open suppression benefit? I have never tried to compare these two approaches.
Andy |
|
|
LarryLeonard
Tomato Guru
USA
1041 Posts |
Posted - Mar 09 2004 : 03:41:45 AM
|
quote: Do you know if "#pragma once" has the same file open suppression benefit?
Yes, it does.quote: I have never tried to compare these two approaches.
I recently totally removed about 300 redundant #includes from a total of about 1000. It had no effect on build time (which was about 15 minutes). I would assume that changing guard defines to #pragma once's would have even less effect. But they are easier to type...
|
|
|
|
Topic |
|