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; clang's clang-cpp should work as well)
  • Python 3 >= 3.10

Installation

pip install include-guard-convert

or run directly using uvx or pipx (replace as wanted)

uvx include-guard-convert FILE1.H FILE2.HPP FILE3.HH

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.2.tar.gz (10.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.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for include_guard_convert-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e0f472f5f5a821302994c46390ad3496e0e1ae12bb53daef461fa0f5d8ba4b68
MD5 6af98b5278971ad8a1161a9964fb6d6b
BLAKE2b-256 b7b1ca9b672f979dfc186e314779506372b071d570341a864cbac861c94427ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for include_guard_convert-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0c344537747dbd77e69e32fa13127e574dc71367d8de3050c85745e3871087dd
MD5 7641de9675449dc9e3dcfaf18aeaea57
BLAKE2b-256 adddd2813ce657e7024d9df1d57eae6d75943ffab8a872515747fcd943793390

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