
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
guardonce
Advanced tools
Include guards suck. They're tiring to type and tedius to update. Worse, the task of updating boilerplate leaves room for copy/paste errors, or other mistakes. #pragma once is simpler and less error prone. That's why you should convert to #pragma once.
Alas, though #pragma once is available on all the most commonly used compilers, it's not available on every compiler. Perhaps one day you'll add support for a platform with a barebones compiler with no support for #pragma once and you'll have to convert back. That's ok. It's easy!
There are three main tools provided by guardonce:
checkguard helps find any broken include guards you may already
have in your project. These should be addressed before converting.
guard2once converts files with include guards into files with
#pragma once directives. This ensures your entire project is
consistently using #pragma once.
once2guard converts files with #pragma once directives back into
files with include guards. This ensures your entire project is
consistently using include guards.
First, check your project for broken headers. To recursively search your project directories for the names of all files that lack proper include guards, use the following command, substituting your project's directory for the quoted string:
checkguard -r "source_directory"
By default, checkguard is very forgiving. It accepts either #pragma once
or anything that looks like an include guard. If you know that all your
guards should match some format, you can be more strict by using -p
to specify a pattern to check against.
If certain files are not supposed to have include guards, feel free to leave them be. Files without include guards are ignored by this next step.
Now, all that remains is converting the headers to use #pragma once:
guard2once -r "source_directory"
You're done! Double check that the result matches your expectations and start using #pragma once in your new code. Know that if you ever need to switch back, it's as simple as:
once2guard -r "source_directory"
If the default guard style doesn't appeal to you, there are a few
options to customize it. Maybe take a look through once2guard --help
or check out a walkthrough for some examples.
FAQs
Utilities for converting from C/C++ include guards to #pragma once and back again
We found that guardonce demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.