Sunday, February 9, 2014

C standard quibbles

This article is a collection of personal quibbles regarding the ISO C standard. Expect it to be updated sporadically.

There have been three major editions of the ISO C standard:

  • C89/C90: The original ISO C standard was published in 1990, and was closely based on the 1989 ANSI C standard. The 1989 ANSI and 1990 ISO standards describe exactly the same language; ISO added some introductory material and renumbered the sections. This web page appears to be a draft of the ANSI version of the standard. The 1995 amendment added digraphs and wide character support.
  • C99: The second version was published in 1999. N1256 includes the full 1999 standard with the three Technical Corrigenda merged into it.
  • C11: The third version was published in 2011. The N1570 draft is freely available, and is very nearly identical to the released standard. (There has been one minor Technical Corrigendum.)

Subtopics (these links work on my GitHub page. TODO: Figure out how to fix that or give up and delete the links):

Saturday, December 28, 2013

Where should the control key be?

Almost all modern computer keyboards place the Caps Lock key immediately to the left of A, with the Shift key below it (next to Z) and the Control key below that, in the lower left corner.

It wasn't always this way.

For example, many of Sun's keyboards (images here) put the Control key immediately to the left of A, and the Caps Lock key in the lower left corner.

If you happen to like the "modern" layout, that's great; I'm not going to try to change your mind, and you can feel free to stop reading now.

But personally, I find it much easier to type when the Control key is immediately to the left of the A key, and the Caps Lock (which I hardly ever use) is either safely out of easy reach or disabled altogether. I use control sequences extensively. I'm a heavy user of vim, I occasionally use Emacs, and I use Emacs-style key bindings in the bash shell. Reaching my left pinky finger down below the shift key every few seconds is quite awkward, but if the control key is on the home row I don't even have to think about it. Yes, I've tried using keyboards with Control below Shift; no, I've never been able to get used to it.

Fortunately, there are ways to remap your keyboard in software so that the key labeled "Caps Lock" acts as a Control key. Unfortunately, those ways vary considerably from one operating system to another.

Monday, November 5, 2012

Markdown

I've decided to start composing and maintaining this blog using Markdown.

If you're not familiar with it (or even if you are), Markdown is a text-to-HTML conversion tool for web writers. Raw Markdown is much more readable and easier to work with than raw HTML. It doesn't directly provide the full power of HTML, though you can include raw HTML in a Markdown document -- and you can do italics, bold, and bold italics directly in Markdown.

It's used (in slightly different flavors) on GitHub and on the StackExchange network of sites, among other places.

All posts on this blog are maintained as a GitHub project. If you're sufficiently curious, you can see the Markdown form of all the articles, and how I've revised them over time.

One thing I've noticed with the composition software used by blogspot.com is that switching between the "HTML" and "Compose" views changes the HTML; in particular, it removes <p> paragraph markup, replacing it by <br /> line breaks. Because of this I need to copy the Markdown-generated HTML into the HTML window and click the Update button without looking at the preview. Annoying, but not fatal.

Markdown is converted to HTML by the markdown command, which is also available as a .deb package on Debian and Debian-derived systems such as Ubuntu and Linux Mint:

sudo apt-get install markdown

It should be available for other systems as well. I run a simple gen-html script (included in the GitHub project for this blog), and then manually copy-and-paste the generated HTML into blogspot.com's web interface. The manual step is annoying, but overall it should make it easier to write and maintain this blog.

Pandoc is another good conversion tool, handles numerous other formats as well. It should be available for most systems.

Who knows, I might even get around to posting more articles!

Last updated Sat 2013-12-28 16:29:29 PST

Monday, March 5, 2012

No, strncpy() is not a "safer" strcpy()

The C standard library declares a number of string functions in the standard header <string.h>.

By the standards of some other languages, C's string handling is fairly primitive. Strings are simply arrays of characters terminated by a null character '\0', and are manipulated via char* pointers. C has no string type. Instead, a "string" is a data layout, not a data type. Quoting the ISO C standard:

A string is a contiguous sequence of characters terminated by and including the first null character.

Friday, January 13, 2012

First post

Greetings to my vast army of followers.

This is my new blog, in which I will sporadically post rants and musings on software development, programming language standards, and whatever else strikes my fancy at the moment.

Welcome.

Last updated Mon 2012-11-05 16:48:00 PST