7

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?

Jin
  • 1,902
  • 3
  • 15
  • 26
  • it is simply a type. A `int*` or `struct A {}*`. Rather than `void*`, `int(*)()` or `struct A; struct A*`. As incomplete (in C only), void and function types are not object types. Read it as `(pointer to object) type`. – Johannes Schaub - litb Aug 20 '16 at 08:33
  • Then are the concepts "pointer to int object" and "pointer to object type" identical? – Jin Aug 20 '16 at 08:35
  • In C++ there is the term "object pointer type" which includes `void*`, but "pointer to object type` does not include `void*`. I think C as no such werid confuseness. – Johannes Schaub - litb Aug 20 '16 at 08:38
  • I guess "(pointer to (object type)) type" is more unambiguous here but more confusing. – Johannes Schaub - litb Aug 20 '16 at 08:39

1 Answers1

4

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*).

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • Oh BTW, have you heard of the concept "expression evaluates to pointer to object" or "expression evaluate to lvalue"? Actually I've asked this question because I coudn't understand that concept (http://stackoverflow.com/questions/39051512/whats-the-point-of-evaluating-left-operand-of-assignment-operator-in-c - Read R Sahu's answer!) – Jin Aug 20 '16 at 08:52
  • @Jin "object" in "expression evaluates to pointer to object" is a way of saying "it is a pointer, but not a function pointer, and not a `void` pointer." `lvalue` means any expression that can be assigned with `=` operator. – Sergey Kalinichenko Aug 20 '16 at 09:06
  • Then is RSahu's comment "`array[index]` evaluates to an object, not to a pointer" an incorrect statement? According to you answer, 'array[index]' should evaluate to a pointer value which designates a float object (if array was declared such that `float array[10]`) – Jin Aug 20 '16 at 14:27