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.1.tar.gz (3.5 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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for include_guard_convert-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d72317e02507e64b5a18119516f0b27c7eff5affb8351a9b3f10396e90f3486e
MD5 b71847fa6a4100e96b4e5c724424962a
BLAKE2b-256 09ab46828948c995393e52d03163eadf7e63706658a6383ad9ebeca452430f7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for include_guard_convert-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8653fcea66f6c05345366005f250e7add0463c10498b0f59ab1d5fcf7fea4e2f
MD5 7309fd01db6608217c2667d011eb60a0
BLAKE2b-256 2e5df720580bcfb29ff3a80c28b26deaa474f2dd60fab041c8b8dd073b1c324b

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