Quantcast
Channel: User CPlus - Programming Language Design and Implementation Stack Exchange
Viewing all articles
Browse latest Browse all 65

Why are symbols (especially static/internal symbols) necessary?

$
0
0

Compiled languages seem to always have to attach some name to any global object, such as a function or global variable, even after they are compiled, but not local variables. As such, languages such as C++ and Swift employ name mangling to ensure that the symbols do not collide with each other. But why do there need to be symbols in the first place?

Although it would make sense for symbols to be preserved separately for debugging reasons, and of course library or object files need to give public symbols names so that other code can reference them, why would it be necessary to store the name of the symbols if the symbols are private anyway (static objects in C for instance), or after the product has already been linked? Local variables are simply identified in the assembly by specific registers or specific pointers to stack memory, so why can global objects apparently not be referenced this way, and have to be referenced by name, even after the project has been compiled and linked?


Viewing all articles
Browse latest Browse all 65

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>