Git Product home page Git Product logo

include-guard-convert's Introduction

include-guard-convert

Converts C/C++ preprocessor include guards from the #ifndef XY_H, #define XY_H to the #pragma once paradigm.

Header files have the problem that they should be included once per compile unit; thus, they usually deploy a scheme that looks like this

/*
 * some funky comment, doxygen, copyright info
 */
#ifndef MY_HEADERFILE_H
#define MY_HEADERFILE_H

class declare_and_define_whatever_you_want
{
...
};
#endif /* maybe a comment that this belongs to MY_HEADERFILE_H */

Since this lead to a few bugs (namely, sometimes there are #define naming conflicts, or copy&paste errors), I've wrote a script to make the same file look like this:

/*
 * some funky comment, doxygen, copyright info
 */
#pragma once

class declare_and_define_whatever_you_want
{
...
};

Dependencies

  • C preprocessor (only tested with the GCC cpp)
  • python 2.3+ (I think. Tested with 2.7.5)

Caveats

  • The include guards should be the surround the whole semantic content of the file. That means that #ifndef must be on the first non-comment, non-whitespace, non-empty line of your source code and that it must end with the matching #ifndef line, which may only be followed by empty or whitespace-only lines.
  • The #define constants must be UPPERCASE_UNDERSCORE_0_TO_9_ONLY style.

include-guard-convert's People

Contributors

hmoffatt avatar marcusmueller avatar z1c0 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.