bearophile wrote, re. <http://plan9.bell-labs.com/sys/doc/comp.html>: > I can see some interesting things in that very C-like language: > >> The #if directive was omitted because it greatly complicates the >> preprocessor, is never necessary, and is usually abused. Conditional >> compilation in general makes code hard to understand; the Plan 9 source uses >> it sparingly. Also, because the compilers remove dead code, regular if >> statements with constant conditions are more readable equivalents to many >> #ifs. > > Can the "static if" be removed from D then?
D uses "static if" for things other than versioning. But this attitude is relevant when considering “enhancements” to D’s version(foo). > I don't fully understand this: > >> the declaration >> extern register reg; >> (this appearance of the register keyword is not ignored) allocates a global >> register to hold the variable reg. External registers must be used >> carefully: they need to be declared in all source files and libraries in the >> program to guarantee the register is not allocated temporarily for other >> purposes. Especially on machines with few registers, such as the i386, it is >> easy to link accidentally with code that has already usurped the global >> registers and there is no diagnostic when this happens. Used wisely, though, >> external registers are powerful. The Plan 9 operating system uses them to >> access per-process and per-machine data structures on a multiprocessor. The >> storage class they provide is hard to create in other ways. Generally, the Plan 9 C compilers ignore the "register" keyword, preferring to handle this sort of optimization themselves. The "extern register" declaration is not for optimization, but to allocate a register as a global variable. This register will never be used by the compiler as a temporary, or to pass arguments, or whatever compilers use registers for; it has been completely given over for the programmer’s use. Apparently, this was helpful in writing the Plan 9 kernel. —Joel Salomon
