Skip to content

Conversation

@rjarry
Copy link
Collaborator

@rjarry rjarry commented Jul 3, 2025

An alternative to include guards using #ifndef, #define and #endif is #pragma once. This non-standard but commonly supported directive among C and C++ compilers, it also requires less code and does not require the definition of a variable with risk of name conflicts. Also, the variable definitions often deviate after file renaming and/or move.

Bonus, the use of #pragma once may improve compilation speed since it is a higher-level mechanism. The compiler itself can compare filenames or inodes without having to invoke the C preprocessor to resolve #ifndef and #endif.

An alternative to include guards using `#ifndef`, `#define` and `#endif`
is `#pragma once`. This non-standard but commonly supported directive
among C and C++ compilers, it also requires less code and does not
require the definition of a variable with risk of name conflicts. Also,
the variable definitions often deviate after file renaming and/or move.

Bonus, the use of `#pragma once` may improve compilation speed since it
is a higher-level mechanism. The compiler itself can compare filenames
or inodes without having to invoke the C preprocessor to resolve
`#ifndef` and `#endif`.

Signed-off-by: Robin Jarry <[email protected]>
@christophefontaine christophefontaine merged commit 87ada60 into DPDK:main Jul 4, 2025
9 checks passed
@rjarry rjarry deleted the pragma-once branch July 4, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants