Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is pointer to object type in C?

Tags:

c

object

pointers

For example,

int x = 10;

Then the value 10 is saved somewhere in the memory. I have heard of "pointer to int object", but I have never heard of "pointer to object type". Does this mean that the object where 10 is stored saves information about the type of value stored in the object and value of "pointer to object type" shows where this information is stored in memory?

like image 284
Jin Avatar asked Aug 20 '16 08:08

Jin


1 Answers

I think the text mentioning "pointer to object type" is talking about the type representing a "pointer to object", i.e. a pointer to something.

Does this mean that the object where 10 is stored saves information about the type of value stored in the object

Type information of variables that you declare in C is relevant only during the process of compiling your program. Once your program has been compiled, type information is gone. There is no type information to store in memory at runtime.

Here is one place where C99 standard mentions "pointer to object type":

6.5.2.1 Array subscripting

One of the expressions shall have type "pointer to object type", the other expression shall have integer type, and the result has type "type"

What this means is that the pointer expression has to be a pointer to data object of a specific type. It cannot be a pointer to function, or a pointer to data with no specific type (i.e. void*).

like image 184
Sergey Kalinichenko Avatar answered Sep 20 '22 18:09

Sergey Kalinichenko