4 ms·
All Plan9 C programs are written in this way. Paradoxically the number of includes in your code is minimal compared with the usual POSIX aproach. All C programs
by pmarin 12y ago
All Plan9 C programs are written in this way. Paradoxically the number of includes in your code is minimal compared with the usual POSIX aproach. All C programs begin with two includes: u.h and libc.h and usually libio.h and it is often all you need for the startdard library.
The man pages of the libraries describe the libraries you need to include.
Example:
Plan9 cat: http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/cat.c http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/cat.c
GNU cat: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/chcon.c;h=32d4b0f8b7aa98830ec6404c83801c5115f29854;hb=HEAD http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f...
Plan9 du: http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/du.c http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/du.c
GNU du: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/du.c;h=890edb64c31a41fdd0bf9a3f24607369c436928f;hb=HEAD http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f...
- Peaker 12y agoSo basically the #include granularity is extremely coarse, because otherwise it is unmanageable. I think it is nicer to have quite specific #include's: #include <stdbool.h> #include <stdarg.h> #include "hash_table.h" Because it: * Gives a list of dependencies at a glance * Along with preprocessor optimizations to avoid reparsing protected headers, it can actually parse fewer headers in each compilation (reversing the performance argument by Rob) * Can aid with greps for where modules are used The comparison is really a strawman -- and the length of the GNU one and its many dependencies relate more to feature creep than to the #include issue here. At least with GNU's #includes, I can see that it depends on the various stuff it needs for its feature creep.
- ufo 12y agoWhy do all the P9 files use `void main` instead of `int main`?
- pmarin 12y agoYes. Instead of returning an integer you use the function exits [1] and the value appears in the shell variable status. [1] http://plan9.bell-labs.com/magic/man2html/2/exits http://plan9.bell-labs.com/magic/man2html/2/exits This is an introduction to programming in Plan9 C: http://doc.cat-v.org/plan_9/programming/c_programming_in_plan_9 http://doc.cat-v.org/plan_9/programming/c_programming_in_pla...