Its well known that we can store DATA in dynamically allocated memory.
However, I was wondering if we can store NEW INSTRUCTIONS or NEW FUNCTIONS on the heap? Any real applications?
Preparing for interviews, so please bear with me if this isn’t a sensible question.
The question is about C language, so the answer should be no — there is nothing in the language alone that defines anything like storing a function on the heap.
However, if we add knowledge of implementation details and OS (relocation tables, page protection, etc), then yes, it’s possible. For example, custom dynamic code loaders (that do not use OS-provided DLL/SO loading) work this way.