Trenchbroom: Replace include guards with #pragma once

Created on 19 Oct 2020  路  5Comments  路  Source: TrenchBroom/TrenchBroom

pragma once has the advantage that it isn't succeptible to copy and paste errors. It is nonstandard, but should be supported by all compilers we use.

3 Maintenance

Most helpful comment

Sure. The plan sounds good. We should give vecmath the same treatment in a separate PR for that repo.

There may be some stray header files elsewhere in the code, too.

All 5 comments

I wouldn't mind knocking this one out just to get my feet wet in the codebase.

My assumptions/steps I would take are as follows:

1) I should only update header files in the /common subdirectory. I assume files in /lib and whatnot are all 3rd party code?

2) Add #pragma once to the top of every header file in those directories. (would there be any headers that we'd want to exclude for some reason?)

3) Remove all instances of the "#ifndef - #define - #endif" dance in those directories.

4) Make sure it all compiles

Does that make sense?

Cool! @kduske we're ok with going ahead with this, right?

  1. Everything in /common can be updated plus /lib/kdl (this is where we put utility code, it lives in the TrenchBroom git repo.) The other directories in /lib are 3rd-party git submodules. (vecmath is not really 3rd party but it's in a separate git repo at https://github.com/TrenchBroom/vecmath ).

  2. My first suggestion would be try to do a regex find/replace so that it stays at the same position under the copyright comment:

 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef KDL_COLLECTION_UTILS_H
#define KDL_COLLECTION_UTILS_H

#include <algorithm> // for std::remove

gets converted to:

 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#pragma once

#include <algorithm> // for std::remove

Sure. The plan sounds good. We should give vecmath the same treatment in a separate PR for that repo.

There may be some stray header files elsewhere in the code, too.

For removing the #endifs at the end of the headers, is it ok to remove the comment too ?

i.e. remove this whole line:

#endif /* defined(TrenchBroom_TextureBrowserView) */

rather then leave the comment intact. /* defined(TrenchBroom_TextureBrowserView) */.

Yep, removing the whole #endif line including comment sounds good

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HeadClot picture HeadClot  路  4Comments

dumptruckDS picture dumptruckDS  路  5Comments

jmickle66666666 picture jmickle66666666  路  3Comments

JackViney96 picture JackViney96  路  4Comments

mikejsavage picture mikejsavage  路  3Comments