Hacker News new | ask | show | jobs
by vidarh 4296 days ago
Looking at code from the 80's, it is quite common to come across code that is extremely explicit about types, and that exploits known type sizes of the target platform, overflow behaviour etc.

E.g. modern C code tends to use "int" or "long" all over the place without considering if "short" or "char" is likely to be sufficient.

Similarly, you'll find bit fiddling wherever it is possible, including a tendency to use bit shift instead of multiply/divide even for constant factors where one might thing the compilers would optimize it to shifts (many early compilers didn't).

So it's not necessarily just an idiom of systems programming, as an idiom amongst "old school" C programmers in general. The extent to which it has carried through to more modern code, varies, though. I suspect systems programming has an overall higher ratio of "old school" C developers than application code does.

1 comments

> E.g. modern C code tends to use "int" or "long" all over the place without considering if "short" or "char" is likely to be sufficient

"Sufficient" is bit odd choice of word here. Word-sized types should be used unless there is a good reason not to. See nkurzs comment for a great example for this:

> The first 'movl' wipes out any bits greater than 32 if they are there. This is because x was defined as an int, and not a long.

https://news.ycombinator.com/item?id=8346336