Skip to main content

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

Project description

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 3 (tested with 3.8.2)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

include_guard_convert-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

include_guard_convert-1.0.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file include_guard_convert-1.0.0.tar.gz.

File metadata

File hashes

Hashes for include_guard_convert-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aa5838cc89474c5bbdc4bb3b5a4c36b4d5dfa413a46a3f6f454a8b9345a8fa1f
MD5 f9464cce501c7d70b592d94bac30bf8e
BLAKE2b-256 af31504c38e3e155bad85b3760896f5d506f9316766bbe919a62d4ba80f24577

See more details on using hashes here.

File details

Details for the file include_guard_convert-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for include_guard_convert-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e78d4b930c1fde009b0fb051f3569de0896075db7d24b947161ed717b9848e6f
MD5 ba5902db3d5c0d7917d2e36f05ade552
BLAKE2b-256 376d5c62d975d7e901f8cfdd901415518c471c0b0de44c5d6fc5ad135f9f69e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page