| A great answer! > I am not sufficiently familiar with the C world to tell you exactly which thing is defined in which part. I've got some bits of knowledge here. I could be wrong, as it's not my expertise... > Function calls have a "stack" and there's a "heap", and the language itself distinguishes between them. I don't believe this is true or at least, not literally but the details are interesting! http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf is what I usually go by when talking about C11. Malloc is defined in 7.22.3.4, and says: > The malloc function allocates space for an object whose size is specified by size and whose value is indeterminate. In 7.22.3, the overview for all the memory functions, it says stuff like > The lifetime of an allocated object extends from the allocation until the deallocation. which restricts how you can implement it, of course, but it doesn't use the words "heap" and "stack" at all; "stack" is never mentioned in the document. 6.2.4 talks about storage durations, this is usually what we think about when we talk about "stack" and "heap" and such. "stack allocated" is more properly termed "automatic storage duration" and "heap allocation" is "allocated storage duration." This is a side effect of the fact that C itself is defined in terms of a virtual machine! They call it the "abstract machine". Anyway, all of this is in service of your point about history and such. Many people just assume all of this is how it has to be, rather than something that came to be thanks to history. It's all very interesting! > C itself, IIRC, has no specification for threads whatsoever, IIRC C11 added this, actually, but before that, you're 100% right. |