在C中识别内存中值的数据类型? [英] Identifying data type of a value in memory in C?

查看:36
本文介绍了在C中识别内存中值的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序/应用程序如何知道内存地址中的数据是某种数据类型.

How does a program/application know that the data in a memory address is of a certain data type.

例如,假设有 int a; 并且假设变量 a 存储在地址 0x100 中.表示它属于 int 类型的存储信息在哪里?

For instance, suppose there is int a; and suppose variable a is stored in address 0x100. Where is the the information stored that says it is of type int?

推荐答案

在像 C 这样的语言中,信息总是以您解释数据的方式存储".编译器添加了一些好处,它在某种程度上理解您的变量的类型并试图阻止没有意义的操作.

In languages like C the information is always "stored" in the way you interpret the data. Some niceness is added by the compiler which to some extent understands the types of your variables and tries to prevent operations which don't make sense.

例如,假设您有以下位:0xFFFFFFFF.如果您将它们解释为32b unsigned int",您将得到 4294967295.如果您将它们解释为32b 签名整数",您将得到 -1(*).如果你将它们解释为双重,天知道你会得到什么.

For instance, suppose you have the bits: 0xFFFFFFFF. If you interpret them as "a 32b unsigned int" you'll get 4294967295. If you interpret them as "a 32b signed int" you'll get -1(*). If you interpret them as a double, god knows what you'll get.

这篇关于在C中识别内存中值的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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