CMPSC 311, Introduction to Systems Programming

The World's Most Boring C Program



Remember the course mantra, System programming requires you to be aware of the resources that your program uses.

This is a lesson about how characters are represented in C, how character strings are stored in C, and how to compile your C programs, even if that's not what it looks like.  There are some exercises at the end; the one marked *** is essential to see if you understand what's going wrong with this program.



Reading
Source code
Test systems
Compilation results, warnings turned off by default
Compilation results, warnings turned on
Compilation results, assembly language output, file boring.s
Execution output
Execution output -- count characters with wc, print characters with od

./boring | wc
./boring | od -c
./boring | od -t a
OK, Unix is supposed to be standardized, so why are there differences in the behavior of the wc and od programs between these three systems?


Exercises
1.  Why does the program boring make a noise when you run it?  (If it doesn't, it should.)

2.  *** The program boring.c is supposed to output 128 characters, but the boring | wc and boring | od -t a  pipelines report only 126 characters.
3.  The output from the boring | od -c pipeline seems to be missing three characters, not just two.  Why? 4.  Try these changes to the program, and explain what happens differently.



Last revised, 7 Jan. 2012