By l0k3ndr

2014-02-12 19:29:24 8 Comments

I am searching for a month for blog posts about "how C program works". Most of them go like

  1. Compilers do these things
  2. Linkers do these things
  3. Program is put into memory; and stacks, heaps, etc.

I thought I would first read about how compiler works to understand the flow of the program into the machine. Dragon Book seems to be universally preferred. But truthfully, it's too intensive. I am not good enough now to go through it all.

So I began to read about hardware. But There too, they explain about buses, I/O signals, structure of memory, writing cache-friendly code etc. But with no proper examples.

But still I could not find myself satisfied or being able to completely visualize the process.

2 hours ago I decided to ask this question.(Since I am scared of It might be not useful to SO community, or off-topic question or other down-votable categories) and I did not find out any post relating to this exactly. There was one about "how compiler does the compilation", but the answers showed that it's too broad a question.

My question is this:

I would like to know how, in depth, a C program works. If you cannot tell me explicitly, please redirect me to a book or another post on another website that can give me the answer to this.

I am here until I get a response. If you have any suggestions regarding this post, tell me. And It is not my first language, so please take all my sentences as being soft and polite.



Along with the accepted answer, there are some very nice links as well as suggestions which give partial answers or the way to proceed further to understanding what I am trying to understand.


@Ernest Friedman-Hill 2014-02-12 19:46:47

The best answer to this question by far comes from the book "The Elements of Computing Systems," by Noam Nisan and Shimon Schocken. This book starts from the simplest possible electronic components, assembles them into a working processor, invents a simple assembly language for it, writes an assembler for that, and ultimately shows you how high-level languages can be compiled onto it. Reading the book, and working all the examples (which use a simulator for the hardware, so no workshop required!), will forever change the way you look at computers; he will literally understand everything from the lowest to the highest levels, and see how they work together. See the book's website for more info.

@l0k3ndr 2014-02-12 19:55:09 , it is opening a gaming-site. ??

@Richard J. Ross III 2014-02-12 19:56:21

Someone pasted the wrong link... I hate it when that happens.

@Daniel Neri 2014-02-12 20:01:31

Correct link:

@l0k3ndr 2014-02-12 20:21:14

I will definitely see it.

@l0k3ndr 2014-02-14 17:14:58

I think that's the best answer to the current question... :)

@Despatcher 2014-02-12 19:56:50

It's too broad a question (as you have observed).

If you really want to understand from bottom up - buy an OLD computer from the 80's off ebay. Sinclair Spectrum/BBC it really doesn't matter but make sure you get plenty of books and manuals that go with it.

You will learn plenty because these machines were well documented and what wasn't documented was discovered and then documented :)

They are also sooooo much simpler than a modern quad core multi-gigabyte memory job. It will all fit inside your head easily

or for a modern start, Arduino or Raspberry pie maybe.

@Vortico 2014-02-12 20:09:36

I disagree. Old machines (unless physical machines before 1940) will not reveal the inner workings any more than AMD64 based machines, for example. In fact they may hide more, since one can easily download the Intel developer manuals and learn the theory of its architecture, whereas you have fewer options for understanding a Z80 to the same extent.

@Despatcher 2014-02-12 21:02:57

The Z80 (not used in the BBC Micro actually) is probably one of the most documented processors. It took me 1 (one) google to get the entire manual & architecture in detail direct from Zilog. Nothing is hidden. 1 (one) google to find a C compiler and assembler. It's all so much simpler and the resources are all out there.

@Skizz 2014-02-13 03:05:15

@Vortico: The thing about the Speccy/BBC is that they didn't really have an OS, so you were generally dealing directly with the hardware. The CPUs were conceptually much simpler than modern ones - there was no caching, no memory managers, no uops translations and superscalar architectures. They just read an instruction, did something, then read the next instruction and so on. That is the one drawback to the RasPi - the hardware is really complex.

@l0k3ndr 2014-02-13 04:07:05

Yeah, doing something like this is my wish too. But it's very much time consuming and might not be possible before holidays.

Related Questions

Sponsored Content

6 Answered Questions

9 Answered Questions

[SOLVED] Is this how the + operator is implemented in C?

10 Answered Questions

[SOLVED] Improve INSERT-per-second performance of SQLite?

27 Answered Questions

[SOLVED] How do you set, clear, and toggle a single bit?

15 Answered Questions

[SOLVED] What is an application binary interface (ABI)?

11 Answered Questions

[SOLVED] How do function pointers in C work?

  • 2009-05-08 15:49:17
  • Yuval Adam
  • 762660 View
  • 1150 Score
  • 11 Answer
  • Tags:   c function-pointers

24 Answered Questions

[SOLVED] Fastest sort of fixed length 6 int array

13 Answered Questions

9 Answered Questions

[SOLVED] Create a JVM programming language

6 Answered Questions

[SOLVED] Question about compilers and how they work

Sponsored Content