> Traditionally to avoid problems with repeated inclusion of a header > file, you put #include guards around it, say in sys/dev/foo.h: > [...]
> With newer compilers this can be replaced by a single line in the > header file: > #pragma once Some newer compilers, perhaps. Unless and until it is standardized, there's no telling what #pramga once might mean to the next compiler to come along - except that, for Eliza reasons, it presumably will be related to doing something only once, but there are a lot of such possibilities. Furthermore, even when implementors agree on the basic meaning, unless and until it is precisely specified and standardized, implementations will differ in corner cases. foo.h #define FOO(x) _Pragma(x) bar.h #define BAR() FOO("once") hdr.h #include "bar.h" #include "foo.h" BAR() Which file gets the include-once semantic? Why or why not? I could make an argument for each of the three (some of the arguments will be stronger than others...but which ones are which will vary by person). > 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'm not sure. I see arguments each way. The biggest problems I see with using it in NetBSD-provided include files: (1) Developers may see it and think it's more portable than it is as a result. Developers are already way too ready to assume that anything that works on their development machines is suitable for release. (2) Unless and until the functionality is standardized, it makes the system gratuitously nonportable. ("Portable between what I think are the currently most popular two compilers" is awfully weak, even if "what I think" is correct.) /~\ The ASCII Mouse \ / Ribbon Campaign X Against HTML mo...@rodents-montreal.org / \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B