Think Tank Workspaces

Plan9 and C programming

These are sure to be very small chapters in my experience messing around with plan9 programming.

Chapter 1 First

;touch first.c
;acme first.c # or use sam below
;sam first.c

Type in the following code

#include <u.h>
#include <libc.h>
main(int, char*[])
	print("Welcome to C on Plan9!\n");

A few things are different such as void being on its own line above the main() function Headers are different most programs need 'u.h' or 'libc.h'

You will wan to run the following commands to compile your programs

; 8c first.c	# compile it
; 8l first.8	# link the object

On arm64 you would use

;7c first.c		# compile
;7l first.7 	# link the object

Now you can run the program

; 7.out
Welcome to C on Plan9!

The Plan9 C dialect is not ANSI or ISO C. It is a variation implemented by Ken Thompson.

You can use additional flags for more strict features.

;7c -FVw first.c
;7l first.7

The files generated in the directory are as follows:

term% ls -l
--rwxrwxr-x M 24 glenda glenda 34926 Aug 12 00:28 7.out
--rwxrwxr-x M 24 glenda glenda 34926 Aug 12 00:33 first
--rw-rw-r-- M 24 glenda glenda   539 Aug 12 00:27 first.7
--rw-rw-r-- M 24 glenda glenda   111 Aug 12 06:51 first.c

We can also give it a better name

7l -o first first.7

This creates a file called: first

The file created is about 111 bytes. Nice and small. But once you create the oject and link it you get the final executable.

You can look deeper into the files:

term% nm first.7

U exits T main U print term% nm 7.out 14030 L Inf 13fb8 L NaN 11984 T badfmt 149d0 L barrier...

You have a procdure called main in first.7. T are the text contained in the object. U is print as implied by the statement that follows it. There is a bunch of proeceudres call or system call's beyond scope of this document but you can research that later.

To post a comment you need to login first.