#pragma once

Taylor R Campbell <[email protected]>
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <20221015192139.2DA18608C5__47501.4839017362$1665861739$gmane$org@jupiter.mumble.net>
[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?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.