tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
#pragma once
[bcc tech-userlevel tech-toolchain, followups on tech-kern]
Traditionally to avoid problems with repeated inclusion of a header
file, you put #include guards around it, say in sys/dev/foo.h:
#ifndef _SYS_DEV_FOO_H_
#define _SYS_DEV_FOO_H_
...
#endif /* _SYS_DEV_FOO_H_ */
With newer compilers this can be replaced by a single line in the
header file:
#pragma once
It's nonstandard, but using #pragma once is maybe a bit less
error-prone -- don't have to have to pollute the namespace with
have-I-been-included macros, and I've made mistakes with copying &
pasting the per-file have-I-been-included macro into the wrong file.
That said, clang has a warning these days to detect this mistake so
maybe traditional #include guards aren't that error-prone.
Thoughts on its use in NetBSD in:
(a) purely internal header files?
(b) header files exposed to potentially out-of-tree kernel modules?
(c) header files exposed to userland?
How reliable/consistent is toolchain support for it? Is it worth
adopting or is the benefit negligible over continuing to use
traditional #include guards? Likely problems with adopting it?
Home |
Main Index |
Thread Index |
Old Index