Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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

GNU cat: 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

GNU du: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f...



So 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.


Why do all the P9 files use `void main` instead of `int main`?


Yes. 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

This is an introduction to programming in Plan9 C:

http://doc.cat-v.org/plan_9/programming/c_programming_in_pla...




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: