What is the oldest line of code still used within Windows?

The thought occurred to me recently that some of what makes up Windows 11 was in Windows 10, and some of what was in Windows 10 came from Windows 8, etc. How far back does it go? What is the oldest line of code that is still used in modern windows? Where did it come from, who wrote it, and is there any way to know?

exit();

Somewhere there is possibly a header that defines version numbers. And there may be a #define for Windows 3 or something. So that’s my guess - some very early version definition.

That’s if you are looking for a single line that has never changed.

Notepad is really old too, so there could be some old pieces of that still around. But it could have all been refactored by now.

A contender could be some of the MS-DOS commands used in Command Prompt, some should predate Windows itself.

(unless the functionality has been abstracted at some point along the way?)

I’d be surprised if there weren’t a certain amount of MS-DOS code somewhere in Windows (any version). Some subroutines have been working right for years, why mess with them?

If you go into control panel / phone and modem you will see some very old dialogue boxes going back to Windows 3.

Microsoft Paint has been around since Windows 1.0 in 1985:

#include <stdio.h>

Nearly every nontrivial C program (and a lot of the trivial ones) has that line near the beginning, often as the very first line. It means “insert the header file for the standard input-output library”, and is necessary before one can use any of the most common input or output functions.

To perhaps give a more informative answer, to what the OP was actually asking: I think the OP was expecting something like “this piece of code draws the mouse cursor on the screen”, or something like that. But that’s well above the level of “a line”. Any single identifiable task like that is going to be a whole function or subroutine. And there are probably some subroutines in Windows that predate all versions of Windows by decades. For instance, the standard algorithm for sorting a list was published in 1961, with only slight improvements since then. Any competent programmer on that level could re-write Quicksort, but outside of a programming class where you’re doing it for a grade, there’s very little reason to: If you need a sorting routine, you just grab one that someone else has already written. I’m quite confident that there’s a Quicksort routine buried somewhere in the Windows code (probably multiple places, because with a project that size, it’s likely that some programmer found it easier to grab and paste in a new copy than to find where some other programmer put it), and the code for that Quicksort might literally date back to the 70s, having been repeatedly copied and pasted since then.

I work on a software product which is older than Windows and there’s a lot of original code still left. It’s a programming language and much of the parser is untouched from the original code, for example. The language has evolved but the basic rules to tokenize a program haven’t changed much in the product’s lifetime.

The Windows API includes a lot of utility functions which probably haven’t been touched much, if at all, since they were written. Take, for example, IntersectRect.This function was probably written fairly early on in the development of Windows because it’s fundamental to a windowing system. Assuming that it was written correctly the first time (which is likely, because the implementation is trivial) there would be no reason to ever change the logic, not even when moving from 16 to 32 bits to 64 bits. The size of the input values may have changed but the logic which determines the intersection of the rectangles likely hasn’t. The code the compiler generates for the function may have changed greatly to take advantage of improvements in CPUs and/or GPUs, but the C source code is likely the same. There are hundreds of functions like this in Windows.

One could be a bit mean and bring up the common heritage Windows has with VMS. Dave Cutler was the architect of both. There are some very big similarities between the two. There were rumours of deals and settlements between DEC and MS over Windows 2000 and DEC’s IP, and maybe there was even some cooperation. So it isn’t impossible (but unlikely) that there is code in there that could trace its origins back to when Bill Gates was still in short pants.

It would be interesting to know how controlled the source code has been for Windows over the years. Done right it should be possible to drill back and find who was responsible for every character of code.

I thought a look through the copyright attribution file in Windows might show some interesting dates. Something may say Copyright 1999, 2001, 2008, and nothing from the original 1999 text is still present, but the notice is included anyway.

The best I could find in a brief search is the page for Windows 8.1 and Server 2012R2. I don’t know what to click on in Windows to see a similar page.

After a brief scan of the page, the earliest date I see is

Copyright 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved.This product uses materials copyright Regents of the University of California.

Which is there because Windows includes parts of FreeBSD. FreeBSD isn’t that old, but it’s roots go back that far. So somewhere, buried in the network stack, may be some lines of code written in the 70s.

This is it in the strictest sense of ‘oldest’. It will be some line of code written years before hand and copied from one program to another. Likely not to be an entire routine where language and environments changes may have been required. That is if it is ‘code’ at all and not a simple directive.

Windows is based on MS-DOS, and the original MS-DOS was written in X86 assembly (and maybe a little C).

It wouldn’t surprise me greatly if there’s still some x86 assembly around in the Windows source that predates any C #include. Not a certainty, and I don’t think that whatever is in current windows is open source so we probably can’t know, but chkdsk was written in assembly as recently as MS DOS 2.0. Might still be?

Maybe the first version. Remember Windows NT (based on VMS)?

In fact Wikipedia says that the WNT kernel is “mostly” written in C, as opposed to VMS’s VAX MACRO assembly.

Sure, that’s the kernel. But are we sure there’s no bit of original MS-DOS that’s still shipped with Windows? There are lots of little Windows utilities that might still contain some original assembly source.

I work for a software company that released software around the same time that Microsoft originally did, and I believe that some of that code still ships. It still works; why would we rewrite it?

Having worked as a developer for some years, I am almost 100% sure that some of the code is still remaining. My reasoning is that complete rewrites of every single line of code of a complex application almost never happens. There is always an impossibly long backlog of stuff to be done. Often things that are really important cannot be prioritized for years. When are you going to get the time to rewrite all your legacy code?

I’d be willing to bet that the oldest piece of C code in Windows is older than the oldest piece of assembly code in Windows. Assembly code can only be as old as the x86 architecture itself, but C code can be older (for instance, the oldest C quicksort was probably written within a month or so of the creation of C).

It is easy enough to look through various header files, but it is not like I have them all, and, also what to look for?

Also note things like that the AvlTable module “refers directly to algorithms as they are presented in the second edition [of Knuth’s book] Copyrighted in 1973”, while the code itself seems to have been copied and pasted by half a dozen people, who knows when.

The earliest Copyright Microsoft Corporation notice I found in 30 seconds is only 1980 (for debug hooks). I only looked at Windows files. There is also some code copied and pasted from BSD, also copyright 1980. Some public-domain crypto code in C from 1977…

Yeah that’s probably true.