Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is pointer metadata stored?

Could be that I am overlooking something obvious, but where is pointer metadata stored? For instance if I have a 32-bit int pointer ptr and I execute ptr++ it knows to advance 4 bytes in memory. However, if I have a 64-bit int pointer it knows to advance 8 bytes. So who keeps track of what type of pointer ptr is and where is it stored? For simplicity you can limit this to C++.

like image 785
bmalicoat Avatar asked Feb 03 '10 06:02

bmalicoat


People also ask

Do pointers store data?

A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory items.

Are pointers stored in memory?

In computer science, a pointer is an object in many programming languages that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory-mapped computer hardware.


2 Answers

It isn't stored anywhere, per-se. The compiler looks at the type of the ptr and turns the ++ operation into an increment of the correct number of bytes.

like image 126
mbarnett Avatar answered Sep 22 '22 03:09

mbarnett


In the symbol table while the compiler runs. Nowhere while your program runs, or rather it is implicit in the lower level code produced by the compiler.

like image 30
dmckee --- ex-moderator kitten Avatar answered Sep 21 '22 03:09

dmckee --- ex-moderator kitten