I somehow have the feeling that modern systems, including runtime libraries, this exception handler and that built-in debugger build up more and more layers between my (C++) programs and the CPU/rest of the hardware.
I’m thinking of something like this:
1 + 2 >> OS top layer >> Runtime library/helper/error handler >> a hell lot of DLL modules >> OS kernel layer >> Do you really want to run 1 + 2?-Windows popup (don’t take this serious) >> OS kernel layer >> Hardware abstraction >> Hardware >> Go through at least 100 miles of circuits >> Eventually arrive at the CPU >> ADD 1, 2 >> Go all the way back to my program
Nearly all technical things are simply wrong and in some random order, but you get my point right?
-
How much longer/shorter is this chain when I run a C++ program that calculates 1 + 2 at runtime on Windows?
-
How about when I do this in an interpreter? (Python|Ruby|PHP)
-
Is this chain really as dramatic in reality? Does Windows really try “not to stand in the way”? e.g.: Direct connection my binary <> hardware?
“1 + 2” in C++ gets directly translated in an
addassembly instruction that is executed directly on the CPU. All the “layers” you refer to really only come into play when you start calling library functions. For example a simpleprintf("Hello World\n");would go through a number of layers (using Windows as an example, different OSes would be different):WriteFilein kernel32WriteFile, notices that the handle is a console and directs the call to the console systemDrawStringcalls inside GDI32.dll (or maybe GDI+?)DrawStringmethod loops through each character in the string and:DrawStringcalls are complete, the final image for the window is sent to the DWM where it’s loaded into the graphics memory of your graphics card, and replaces the old windowNow there’s a lot of layers that I’ve simplified (e.g. the way the graphics card renders stuff is a whole ‘nother layer of abstractions). I may have made some errors (I don’t know the internals of how Windows is implemented, obviously) but it should give you an idea hopefully.
The important point, though, is that each step along the way adds some kind of value to the system.