tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: #pragma once



On Sat, Oct 15, 2022 at 07:21:35PM +0000, Taylor R Campbell wrote:
 > [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.

I don't see any benefit given that it's maybe 5-10 minutes with sed to
write a script to detect wrong include guards.

Furthermore since we still don't have a clear separation between
internal and user-facing kernel headers, there's no significant place
we can safely/correctly use the pragma that will help much.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index