473,803 Members | 3,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference

what is the difference between objects and pointers?
Nov 14 '05
59 3583
Richard Bos wrote:

pete <pf*****@mindsp ring.com> wrote:
Richard Bos wrote:

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


The result of the & operator, is a pointer, though not an object.


My hovercraft, OTOH, is full of eels - which is just as relevant.


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
Nov 14 '05 #11
pete wrote:
Richard Bos wrote:
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>.


The result of the & operator, is a pointer, though not an object.


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
Nov 14 '05 #12
Hallvard B Furuseth wrote:

pete wrote:
Richard Bos wrote:
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>.
The result of the & operator, is a pointer, though not an object.


Are you sure? Where does the standard say this?

The program has to put the result somewhere
- maybe in memory, maybe in a register.


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.
That place isn't named by a variable or anything else, but
I don't see what that has to do with it.


--
pete
Nov 14 '05 #13
In 'comp.lang.c', Richard Heathfield <in*****@addres s.co.uk.invalid > wrote:
A pointer *is* an object.


Not necessarily. In this code fragment:

int i;
int *p = &i;

&i is a pointer, but not an object.


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- em**********@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/
Nov 14 '05 #14
Hallvard B Furuseth wrote:
pete wrote:
Richard Bos wrote:
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>.


The result of the & operator, is a pointer, though not an object.

Are you sure? Where does the standard say this?


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: <bp**********@c tb-nnrp2.saix.net>

--
Thomas.

Nov 14 '05 #15
Emmanuel Delahaye wrote:
Richard Heathfield <in*****@addres s.co.uk.invalid > wrote:
A pointer *is* an object.


Not necessarily. In this code fragment:

int i;
int *p = &i;

&i is a pointer, but not an object.


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.


And, in the above context:

int *p = c & i;

is probably a silly error, due to the appalling overuse and
overloading of symbols in C in context sensitive manners. We
won't fix this now, but I just thought I would rant and rave a
bit. Wasn't it the Queen of Hearts who said "it means just what I
intend it to mean".

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #16
Ramkumar R K wrote:

what is the difference between objects and pointers?


comp.lang.c is not a substitute for reading your C book.

what is the difference fruit and apples?
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #17
Richard Heathfield wrote:

Richard Bos wrote:
ra********@indi atimes.com (Ramkumar R K) wrote:
what is the difference between objects and pointers?


A pointer is an object,


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

Don't fight it so hard. "pointer to the address of" indeed. I contend
simply that we confuse "address" and "pointer" too often. An address is
a value with pointer type but it is a value, not an object. The value
yielded by the & operator is an address. Calling it a pointer is wrong.
Expressing the name of a function yields the address of it. Not a
pointer.

We all know that C is value oriented. We pass arguments to functions by
value. Functions return values to their callers. But we 'say' it wrong.
Because the value returned is of pointer type we call it 'pointer'
instead of value. Example..

int *p; /* p is a pointer to int */
p = malloc(N * sizeof *p);

The return from malloc() is a value of type (void*). The value is
assigned to p, the only pointer around.

I commend the reader to the first sentence of Chapter 5 of K&R 1 and 2.
"A pointer is a variable that contains the address of another variable."

What's so hard about this?
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #18
Joe Wright wrote:
Richard Heathfield wrote:

Richard Bos wrote:
> ra********@indi atimes.com (Ramkumar R K) wrote:
>
>> what is the difference between objects and pointers?
>
> A pointer is an object,
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).

Don't fight it so hard. "pointer to the address of" indeed.


Sorry about that. I meant, of course, "a pointer to that function".
I contend
simply that we confuse "address" and "pointer" too often. An address is
a value with pointer type but it is a value, not an object. The value
yielded by the & operator is an address. Calling it a pointer is wrong.
I agree that the value is an address, but disagree that calling it a pointer
is wrong. The Standard says:

"The unary & operator returns the address of its operand. [...]
the result is a pointer to the object or function designated by its
operand."
Expressing the name of a function yields the address of it. Not a
pointer.


See above.

<snip>

--
Richard Heathfield : bi****@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
Nov 14 '05 #19

On Mon, 26 Jan 2004, Joe Wright wrote:

Richard Heathfield wrote:
Richard Bos wrote:

A pointer is an object,
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).


Don't fight it so hard. "pointer to the address of" indeed.


We all have our terminological quirks. Indeed, I would contend that
Richard's use of "pointer to the address of" is silly -- a pointer,
to me, *is* an address (or, equivalently, the value of a pointer
object is an address). A pointer points to an object, not an address!
:-) Obviously, SMV [someone's mileage varies], or it could have been
a thinko.
I contend simply that we confuse "address" and "pointer" too often.
An address is a value with pointer type but it is a value, not an
object. The value yielded by the & operator is an address.
Agreed.
Calling it a pointer is wrong.
Disagreed. (Would you object to my calling 5 an 'int', even though
it's not an object? ...And that's not even getting into the debate
that hit c.s.c a year or so ago, when it seemed like maybe 5 *was*
an object, just not an lvalue... I don't remember the details.)
Expressing the name of a function yields the address of it. Not a
pointer.
Just as many people call the value 5 an int, many people will
continue to call &foo a pointer no matter how consistent it might
be to go the other way. :)
We all know that C is value oriented. We pass arguments to functions by
value. Functions return values to their callers. But we 'say' it wrong.
Because the value returned is of pointer type we call it 'pointer'
instead of value.
Exactly.
I commend the reader to the first sentence of Chapter 5 of K&R 1 and 2.
"A pointer is a variable that contains the address of another variable."

What's so hard about this?


I'm actually pleasantly surprised that K&R1 Ch5 manages to keep
the concepts of 'pointer object' and 'address value' separate as much
as they do. Way to go, K&R! But I don't like how they appropriated
the word "pointer" to describe those pointer objects, because, as you've
observed above, we *do* use the word "pointer" to refer to values of
pointer type.

Bottom line: Avoid arguing over the semantics of "pointer." Stick
to "object" and "value" in pedantic contexts, because they have almost
unambiguous meanings in C.

-Arthur
Nov 14 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
7116
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
21
3023
by: b83503104 | last post by:
Hi, Can someone tell me the difference between single quote and double quote? Thanks
26
4423
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: starttime = Date.parse("Aug 10,2003, 07:07") sdt = new Date(starttime)
21
2855
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c = 0, d = 0, e = 0; for(int n = 0; n != 6000000; n++) { a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2; b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2; c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
4
15759
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow which calculated the difference in years and days between two dates, and takes leap years into account? I'm calculating the difference in the usual way, i.e....
3
4164
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second column I have to show difference between Currenttime and date from ItemReceived. How can I do that.
12
2721
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
5
3490
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference: 1 day, 1hour
9
2683
by: viki1967 | last post by:
Hi all! This new forum its great! :) Congratulations !!! My answer: why this my code not working? Nothing error but not work the difference.... : <html>
11
12128
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my code is just returning me an array of 0's
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10550
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.