Explain this implementation of malloc from the K&R book

Ok, what we have here is a chunk of really poorly written code. What I will do in this post could best be described as software archaeology. Step 1: fix the formatting. The indention and compact format doesn’t do anyone any good. Various spaces and empty rows need to be inserted. The comments could be … Read more

Signal EOF in mac osx terminal

By default, macOS (formerly OS X and Mac OS X) software recognizes EOF when Control-D is pressed at the beginning of a line. (I believe this behavior is similar for other versions of Unix as well.) In detail, the actual operation is that, when Control-D is pressed, all bytes in the terminal’s input buffer are … Read more

How can a C compiler be written in C? [duplicate]

It’s called Bootstrapping, quoting from Wikipedia: If one needs a compiler for language X to obtain a compiler for language X (which is written in language X), how did the first compiler get written? Possible methods to solving this chicken or the egg problem include: Implementing an interpreter or compiler for language X in language … Read more

Alternative (K&R) C syntax for function declaration versus prototypes

The question you are asking is really two questions, not one. Most replies so far tried to cover the entire thing with a generic blanket “this is K&R style” answer, while in fact only a small part of it has anything to do with what is known as K&R style (unless you see the entire … Read more

What are the applications of the ## preprocessor operator and gotchas to consider?

One thing to be aware of when you’re using the token-paste (‘##‘) or stringizing (‘#‘) preprocessing operators is that you have to use an extra level of indirection for them to work properly in all cases. If you don’t do this and the items passed to the token-pasting operator are macros themselves, you’ll get results … Read more