A question about Pointers

Hi.
We all know that a pointer is 4 bytes.
first two bytes are for segment address and two second bytes are for local address.(if __FLAT__ is defined)
I want to know when we create a char pointer and an int pointer (according to above explanation) what is difference between these two pointers?
I mean how compiler understands which pointer is for which data type?
Is there any other information that compiler saves about each variable?
We all know that a pointer is 4 bytes.
Not necessarily.

first two bytes are for segment address and two second bytes are for local address.(if __FLAT__ is defined)
Not necessarily. It's not an if-and-only-if situation.

I mean how compiler understands which pointer is for which data type?
Compile time type information. The compiler keeps track of the different static variables and objects and their types.

Is there any other information that compiler saves about each variable?
At compile time that's of any use to you, only its size (which is technically part of the type information).
Last edited on
Well, the more general question is, how does a compiler know that a series of bytes is anything?

An int, a string, a double, a pointer?

It's the job of the compiler to enforce language feature X which pertains specifically to language Y.

That could include type-information, scope information, vtbls, reference counts (for something like Java that has gc), or whatever else that gives that series of bytes meaning (semantics) in that language. The compiler must keep enough information to enforce the language specifications. If a language is weakly typed, it may just turn the variable into whatever type the function argument desires (there are languages like this). In that case, type information may not be needed.

FWIW, when you do something like casting in C/C++, you are telling the compiler to ignore that bookkeeping information used for typing and make that series of bytes mean something else you specify.
Topic archived. No new replies allowed.