指针类型 [英] Type of Pointer

查看:65
本文介绍了指针类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




众所周知,Pointer只是持有地址。但是机器如何知道指针持有一个Integer的地址,所以我只需要4个字节就可以读取4个字节。它是机器

决定还是编译器在后端做某事?


希望我会得到一些好的回应


问候

谢谢

Hi

It is well known that Pointer just holds address. But how the machine
came to know that the pointer is holding an address of an Integer so i
will read just 4 bytes and in case of Long 8 bytes. Is it the machine
which decides or compiler does something in the back end ?

Hope i will get some good response

Regards
Thanks

推荐答案

7月2日下午3:50,atif< ; atif.aq ... @ gmail.comwrote:
On Jul 2, 3:50 pm, atif <atif.aq...@gmail.comwrote:




众所周知Pointer只是持有地址。但是机器如何知道指针持有一个Integer的地址,所以我只需要4个字节就可以读取4个字节。它是机器

决定或编译器在后端做某事吗?
Hi

It is well known that Pointer just holds address. But how the machine
came to know that the pointer is holding an address of an Integer so i
will read just 4 bytes and in case of Long 8 bytes. Is it the machine
which decides or compiler does something in the back end ?



这与此新闻组讨论的主题有点无关。

然而,仅供参考,机器没有指针的概念。 (因为

机器没有类型的概念)。编译器是

完成所有簿记并相应地生成代码。


-Neelesh

This is somewhat unrelated to the topics discussed on this newsgroup.
However, FYI, the machine has no concept of "pointers" (because the
machine doesnot have concept of "types"). It is the compiler which
does all the bookkeeping and generates code accordingly.

-Neelesh


在2007-07-02 12:50,atif写道:
On 2007-07-02 12:50, atif wrote:




很好知道Pointer只是持有地址。但是机器如何知道指针持有一个Integer的地址,所以我只需要4个字节就可以读取4个字节。是机器

哪个决定或编译器在后端做某事?


希望我能得到一些好的回复
Hi

It is well known that Pointer just holds address. But how the machine
came to know that the pointer is holding an address of an Integer so i
will read just 4 bytes and in case of Long 8 bytes. Is it the machine
which decides or compiler does something in the back end ?

Hope i will get some good response



我想这会回答你的问题:机器不知道任何东西,对于计算机而言,内存只是一长串字节。那么

给定指定地址的字节数取决于你解释它的方式是多少,它可能是一个整数,一个地址,一个浮点数或一个空格

string(char数组),由编译器生成代码,

正确解释数据。


所以假设你在某个地方有一些代表一个地址的字节,然后编译器必须生成代码,这样当你读取那个内存时你会读取在4个字节中,并将其视为一个整数,

如果它是一个长而不是编译器将生成的代码读取8

字节并将其视为长整数。 />

-

Erik Wikstr?m

I think this will answer your question: the machine does not know
anything, to the computer the memory is just a long array of bytes. So
given a number of bytes at a specified address what it is depends on how
you interpret it, it might be an integer, an address, a float or a short
string (char array), it''s up to the compiler to generate code that
interprets the data correctly.

So lets say you have some bytes somewhere that represents an address to
an integer, then the compiler will have to generate code so that when
you access that memory you read in 4 bytes and treats it as an integer,
if it was a long instead the compiler will generate code which reads 8
bytes and treats it like a long.

--
Erik Wikstr?m


我相信编译器可以处理它。编译器应在您编译的二进制文件中插入

机器代码(或汇编语言代码),以便

评估正确的编号。每次尝试访问int或

时的字节数。


但这只是我的猜测。


为char变量分配内存时,是否分配1个字节

或4个字节?

I believe the compiler takes care of it. The compiler should inserts
machine code (or assembly language code)in your compiled binary for
assessing the right no. of bytes everytime you try to access an int or
whatever.

But thats just my guess.

When you allocate memory for a char variable does it allocate 1 byte
or four bytes?


这篇关于指针类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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