[Solved] Where are programming language functions in memory located? [closed]


Yes, functions are located in a specific place in memory. In the context of Virtual Memory (opposed to physical caches), they are stored below the Heap and below a section called the Data (global variables) in a section called Text. All of this is loaded up when the executable is read; this is all done in binary, which is one-to-one with assembly, so you’ll never see this in your C code. However, if you know the processor well, you can sometimes still manipulate it into reading from the code section in your code. It may cause a segfault however, and generally you cannot write to the code section.

Just like pointers to variables, function pointers point to a place on the overall stack (see this helpful site). There is actually a register devoted to pointing to exactly which instruction the program is currently executing.

Class definitions and member functions also have a specific place on the stack; I’m not entirely sure, but I believe they go in Data.

3

solved Where are programming language functions in memory located? [closed]