编译器如何以及在内存中的何处存储有关变量类型的信息? [英] How and where in memory does the compiler store the information about what type a variable is?

查看:46
本文介绍了编译器如何以及在内存中的何处存储有关变量类型的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,编译器必须存储变量 x 是 unsigned int 还是 signed int、float 或其他类型的信息,但在哪里以及如何存储?

Obviously the compiler has to store the information whether variable x is unsigned int or signed int, float or whatever, but where and how?

有某种查找表吗?我在内存中的哪里可以找到它,在可执行文件的哪个部分?

Is there some sort of lookup table? Where in memory do I find it, in which section of the executable?

推荐答案

它是隐式的,在编译器选择的指令中.

It is implicit, in the instructions that the compiler chose.

例如,如果地址 18 包含一个 float,编译器可能会使用一条指令从地址 18 加载一个浮点寄存器.如果它在地址 20 的邻居包含一个 int,编译器可能会从前一个地址+2加载一个整数寄存器.

For instance, if address 18 contained a float, the compiler may use an instruction to load a floating-point register from address 18. And if it's neighbor at address 20 contained an int, the compiler may load an integer register from the previous address + 2.

如前所述,编译器有一个符号表,所以它知道所有变量的位置.这允许它选择正确的指令.但是您不能简单地从单个指令中推导出该符号表的内容.

As already mentioned, the compiler has a symbol table so it knows where all variables are. This allows it to pick the right instructions. But you can't simply derive the contents of that symbol table from individual instructions.

这篇关于编译器如何以及在内存中的何处存储有关变量类型的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆