what is the difference between objects and pointers?
difference
Collapse
This topic is closed.
X
X
-
Ramkumar R KTags: None -
Hallvard B Furuseth
Re: difference
Ramkumar R K wrote:
[color=blue]
> what is the difference between objects and pointers?[/color]
An object is 'a region of data storage in the execution environment, the
contents of which can represent values'. (Quoted from the standard.)
E.g. an integer, struct, malloced area, pointer, or whatever.
So 'int i;' declares an object (and names it 'i').
A pointer is an object which contains the address of another object (or
of a function). E.g. `int *p;'. If you set p = &i, you can access `i'
either through its name `i' or by following the pointer (with the `*'
operator): `*p'.
--
Hallvard
-
Mike Wahler
Re: difference
"Ramkumar R K" <ramkumarrk@ind iatimes.com> wrote in message
news:745db0d3.0 401252259.2ebf4 cd6@posting.goo gle.com...[color=blue]
> what is the difference between objects and pointers?[/color]
A pointer *is* an object. The difference between objects
of pointer type and those of other types, is that pointer types
are used for storing addresses, and other types store other
types of data, e.g. 'int', 'float', a user defined type
(a class or struct), etc.
-Mike
Comment
-
Richard Bos
Re: difference
ramkumarrk@indi atimes.com (Ramkumar R K) wrote:
[color=blue]
> what is the difference between objects and pointers?[/color]
A pointer is an object, an object is not necessarily a pointer.
You can have pointer values, which are values of pointer objects, but it
makes little sense to talk of an object value (as opposed to <sometype>
value or simply value).
Pointers can point at pointers, but objects cannot object to objects.
Richard
Comment
-
Richard Bos
Re: difference
Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
[color=blue]
> A pointer is an object which contains the address of another object (or
> of a function).[/color]
Or possibly of itself <g>.
Richard
Comment
-
pete
Re: difference
Richard Bos wrote:[color=blue]
>
> Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
>[color=green]
> > A pointer is an object which contains
> > the address of another object (or of a function).[/color]
>
> Or possibly of itself <g>.[/color]
The result of the & operator, is a pointer, though not an object.
--
pete
Comment
-
Richard Bos
Re: difference
pete <pfiland@mindsp ring.com> wrote:
[color=blue]
> Richard Bos wrote:[color=green]
> >
> > Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
> >[color=darkred]
> > > A pointer is an object which contains
> > > the address of another object (or of a function).[/color]
> >
> > Or possibly of itself <g>.[/color]
>
> The result of the & operator, is a pointer, though not an object.[/color]
My hovercraft, OTOH, is full of eels - which is just as relevant.
Richard
Comment
-
Richard Heathfield
Re: difference
Mike Wahler wrote:
[color=blue]
> "Ramkumar R K" <ramkumarrk@ind iatimes.com> wrote in message
> news:745db0d3.0 401252259.2ebf4 cd6@posting.goo gle.com...[color=green]
>> what is the difference between objects and pointers?[/color]
>
> A pointer *is* an object.[/color]
Not necessarily. In this code fragment:
int i;
int *p = &i;
&i is a pointer, but not an object.
--
Richard Heathfield : binary@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Comment
-
Richard Heathfield
Re: difference
Richard Bos wrote:
[color=blue]
> ramkumarrk@indi atimes.com (Ramkumar R K) wrote:
>[color=green]
>> what is the difference between objects and pointers?[/color]
>
> A pointer is an object,[/color]
Exceptions include the value yielded by the & "address-of" operator, and the
unadorned name of a function (which is converted to a pointer to the
address of that function, but AFAICT is not an object).
--
Richard Heathfield : binary@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Comment
-
Richard Bos
Re: difference
Richard Heathfield <invalid@addres s.co.uk.invalid > wrote:
[color=blue]
> Mike Wahler wrote:
>[color=green]
> > "Ramkumar R K" <ramkumarrk@ind iatimes.com> wrote in message
> > news:745db0d3.0 401252259.2ebf4 cd6@posting.goo gle.com...[color=darkred]
> >> what is the difference between objects and pointers?[/color]
> >
> > A pointer *is* an object.[/color]
>
> Not necessarily. In this code fragment:
>
> int i;
> int *p = &i;
>
> &i is a pointer, but not an object.[/color]
AFAICT, &i is an expression with pointer type, evaluating to a pointer
value, but p is the only pointer.
Then again, it's a pain to search a document for the definition of
"pointer, but not pointer type or pointer value or object of pointer
type", but the C99 Standard _seems_ to use "pointer" both in contexts
where it must mean "a value of a pointer object" (conversion) and in
contexts where it must mean "an object of pointer type" (increment), so
if _they_ don't have to be consistent about it, I don't see why we
should.
Richard
Comment
-
pete
Re: difference
Richard Bos wrote:[color=blue]
>
> pete <pfiland@mindsp ring.com> wrote:
>[color=green]
> > Richard Bos wrote:[color=darkred]
> > >
> > > Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
> > >
> > > > A pointer is an object which contains
> > > > the address of another object (or of a function).
> > >
> > > Or possibly of itself <g>.[/color]
> >
> > The result of the & operator, is a pointer, though not an object.[/color]
>
> My hovercraft, OTOH, is full of eels - which is just as relevant.[/color]
That the result of the & operator, is a pointer, and not an object,
is completely relevant to OP's question of
"what is the difference between objects and pointers?"
when OP is being told that pointers are objects.
A pointer isn't necessarily an object.
Pointer is a catagory of types, with each type of pointer
being a pointer to some other type.
All constants are of object type also, not just objects.
--
pete
Comment
-
Hallvard B Furuseth
Re: difference
pete wrote:[color=blue]
>Richard Bos wrote:[color=green]
>>Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
>>[color=darkred]
>>> A pointer is an object which contains
>>> the address of another object (or of a function).[/color]
>>
>> Or possibly of itself <g>.[/color]
>
> The result of the & operator, is a pointer, though not an object.[/color]
Are you sure? Where does the standard say this?
The program has to put the result somewhere - maybe in memory, maybe in
a register. That place isn't named by a variable or anything else, but
I don't see what that has to do with it. (Or the value could be
optimized away, of course, but so can other objects.)
--
Hallvard
Comment
-
pete
Re: difference
Hallvard B Furuseth wrote:[color=blue]
>
> pete wrote:[color=green]
> >Richard Bos wrote:[color=darkred]
> >>Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
> >>
> >>> A pointer is an object which contains
> >>> the address of another object (or of a function).
> >>
> >> Or possibly of itself <g>.[/color]
> >
> > The result of the & operator, is a pointer, though not an object.[/color]
>
> Are you sure? Where does the standard say this?
>
> The program has to put the result somewhere
> - maybe in memory, maybe in a register.[/color]
The result does not imply storage according
to the representation of the type,
on the abstract machine, and that's why it's not an object.
[color=blue]
> That place isn't named by a variable or anything else, but
> I don't see what that has to do with it.[/color]
--
pete
Comment
-
Emmanuel Delahaye
Re: difference
In 'comp.lang.c', Richard Heathfield <invalid@addres s.co.uk.invalid > wrote:
[color=blue][color=green]
>> A pointer *is* an object.[/color]
>
> Not necessarily. In this code fragment:
>
> int i;
> int *p = &i;
>
> &i is a pointer, but not an object.[/color]
As I undersdand it, &i is a pointer constant (like NULL in a pointer
context, or the name of an array). It's not a object because it's a constant
value. Constant values have no address. Hence, the assertion "a pointer is an
object" sounds good to me. Please, let me know if I'm wrong.
--
-ed- emdelYOURBRA@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Comment
-
Thomas Stegen
Re: difference
Hallvard B Furuseth wrote:[color=blue]
> pete wrote:
>[color=green]
>>Richard Bos wrote:
>>[color=darkred]
>>>Hallvard B Furuseth <h.b.furuseth(n ospam)@usit.uio (nospam).no> wrote:
>>>
>>>
>>>>A pointer is an object which contains
>>>>the address of another object (or of a function).
>>>
>>>Or possibly of itself <g>.[/color]
>>
>>The result of the & operator, is a pointer, though not an object.[/color]
>
>
> Are you sure? Where does the standard say this?[/color]
I think it falls down to the fact the standard does not say to
much explicitly, but rather on how it uses the term.
Me and Joe Wright had a discussion about this some time back.
If you want to see the arguments made then Message id of starting post
is: <bp5gde$p9a$1@c tb-nnrp2.saix.net>
--
Thomas.
Comment
Comment