Warning: there may be occasional oddness due to css and blog edits. **remodel of posts done. Overhaul of pages (distilled) in progress 3/9

Sunday, September 6, 2026

A question of C on FreeBSD

Something I have realized is that we have FreeBSD ports, various teams for the FreeBSD operating system and its constituent parts, plenty of ways to find information, and a number of mostly complete handbooks, but I am not aware of anything being written and promoted enough to be discoverable, about how one would write software from FreeBSD.  While I was in school, I was exposed to five different programming languages, including C and Pascal.  Two of the other languages I may look into whether there is any support at all but it seems doubtful, and assembly can be useful and extremely efficient but its beyond tedious for anything large I might attempt.  LOGO has its value, mostly with younger kids and its methods may be very well suited for certain kinds of graphics.  BASIC is all but forgotten and of very limited utility even if it is still used somewhere, and I do not mean the extended versions that came later but the most rudimentary line-number based version you would find on an Apple II.

This may become multiple posts, at least two, if I try to do something with C and also try something with Pascal.  Either one will mean quite a bit of remembering what I learned all those years ago and probably re-learning some portion of them since I have used none of it for a very long time.  I keep saying that there should be software for FreeBSD, that we depend too heavily on what Linux provides, and then also complain how Linux either is very inconsistent or that it is then in charge and makes all the decisions whether we like them or not.  Maybe its time to attempt to write software, to go through the process and show how it can be done.  I use FreeBSD so I will describe what is available to us, how to use it, and if I make anything significant it can be on my github.

The FreeBSD Developer's Handbook seems aimed at those who wish to contribute to FreeBSD itself rather than for developing software separate from it.  This will still be helpful, and although it warns that some parts are incomplete or possibly in need of update, it is still going to cover a part of what I will need to know.  In a FreeBSD forum thread called C programming with FreeBSD, one post from Maturin fairly succinctly begins with the gist of what I would do.  A youtube video from the TheUrbanPenguin promises to show me how to get a few easy C programs written from within FreeBSD, so maybe this will be what I may follow along and attempt for my first bits of code.

What Maturin mentioned in their post was also mentioned in the video, although TheUrbanPenguin also modifies the simple hello program twice, adding a little complexity.

As in any other unix[like] system:
  1. write your source code with the texteditor of your choice (preinstalled on FreeBSD are vi, and ee; install other(s) you like.)
  2. (in shell) compile the source e.g. cc my_hello_world.c
  3. correct it, if there were bugs 😁
  4. run your program e.g. ./a.out
The standard default command on any unix[like] system is always cc for "c compiler", that's a link to the system's primary default c-compiler which in FreeBSD is clang(1), https://en.wikipedia.org/wiki/Clang , https://clang.llvm.org/ You may also use options after cc as you use the compiler with its direct name: cc my_hello_world.c -o hello ./hello

The code that TheUrbanPenguin writes in his examples are increasingly complex but remain rather simple since they are only an introduction to writing C code.

#include  //preprocessor command to include header

int main() {
		printf("Hello World\n");
		return 0;
}


#include  //preprocessor command to include header

int main( int argc, char *argv[]) {
		if(argc == 1) {
			printf("Hello World\n");
			return 1;
		} else {
			printf("Hello %s\n", argv[1]);
			return 0;
		}		
}


#include  //preprocessor command to include header
#include  //preprocessor command to include header

int main() {
		printf("Hello %s\n", getenv("user"));
			return 0;
		}		
}

This all seems simple and easy to do, while as I write this I have not yet done.  However, the examples lead me toward some of my recent shell scripts.  Perhaps I could turn those into C at least as more practice, and also because they interact with the system in a number of ways, I would need to learn how to do those things from C as well, surely with more header includes.

Surely programming had a somewhat daunting aura about it, expecting I need a certain environment or tool in order to succeed, an Integrated Development Environment (IDE) but it turns out that truly, except for some resources like a C programming book, or descriptions of various libraries I may need to include, everything is already present in a FreeBSD install.  I may write my blog using bluefish, but I might likely use vi for coding, at least until my efforts become too large, and then I might try an IDE or use the helpful code highlighting features of the bluefish editor.  Right now I have more time than I can fill in a day, mostly, so this interest has been on my mind a bit more.  I learned the languages a long time ago, it was fun, I was able to understand it then, but somehow I lacked the motivation.

Now we both know what it takes to write a C program on our FreeBSD system and its not really a big deal, just get started and see where that leads, do you have an idea for your project?  Try the above and see what happens.

No comments:

Frequently viewed this week