Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signed as default in C

Tags:

c

standards

Once again, I'm teaching a class where I get to answer students questions about C. Here's one I don't know the answer to: Was there a rationale behind accepting signed as the default modifier for C? One would have thought unsigned was the natural choice. So, was this really a design decision?

like image 235
Dervin Thunk Avatar asked Sep 04 '13 01:09

Dervin Thunk


1 Answers

In terms of the standard (since your question is tagged as such), signed was marked as the default because that's how it was with the C implementations that came before the standard.

The original ANSI/ISO standard mandates were to codify existing practice rather than create a new language. Hence the behaviour of pre-standard implementations was the most important factor, as per the rationale document:

The original X3J11 charter clearly mandated codifying common existing practice, and the C89 Committee held fast to precedent wherever that was clear and unambiguous.

The vast majority of the language defined by C89 was precisely the same as defined in Appendix A of the first edition of The C Programming Language by Brian Kernighan and Dennis Ritchie, and as was implemented in almost all C translators of the time. (This document is hereinafter referred to as K&R.)

If you're looking to find out why the pre-standard implementations preferred signed, you'll probably have to look into the architecture of the PDP-n machines for which UNIX and C were originally developed.

The History of C page shows that unsigned was actually a relative latecomer to the language, appearing sometime in the mid '70s:

During 1973-1980, the language grew a bit: the type structure gained unsigned, long, union, and enumeration types, and structures became nearly first-class objects (lacking only a notation for literals).

like image 70
paxdiablo Avatar answered Oct 23 '22 13:10

paxdiablo