Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Reference to Pointer

Reply
Thread Tools

Reference to Pointer

 
 
bansalvikrant@gmail.com
Guest
Posts: n/a
 
      07-02-2009
Hi,

C++ supports reference to pointer . I am wondering why C does not
support referece to pointers ?

Thanks
Vikrant
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      07-02-2009
On 2 July, 07:55, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:

> C++ supports reference to pointer . I am wondering why C does not
> support referece to pointers ?


because C does not support references.

Then it becomes an "ask Dennis Richie question". He designed the
language and for some reason decided he didn't need references.
C is a very small and simple language that is close to the machine,
presumably references were just an abstraction that didn't seem
necessary (if, indeed, anything like references was even considered).

what do you want a reference to a pointer for? Will a pointer to
a pointer do?


--
A designer knows he has achieved perfection
not when there is nothing left to add,
but when there is nothing left to take away.
Antoine de Saint-Exupéry
 
Reply With Quote
 
 
 
 
bansalvikrant@gmail.com
Guest
Posts: n/a
 
      07-02-2009
On Jul 2, 12:26*pm, Nick Keighley <(E-Mail Removed)>
wrote:
> On 2 July, 07:55, "(E-Mail Removed)" <(E-Mail Removed)>
> wrote:
>
> > C++ supports reference to pointer . I am wondering why C does not
> > support referece to pointers ?

>
> because C does not support references.
>
> Then it becomes an "ask Dennis Richie question". He designed the
> language and for some reason decided he didn't need references.
> C is a very small and simple language that is close to the machine,
> presumably references were just an abstraction that didn't seem
> necessary (if, indeed, anything like references was even considered).
>
> what do you want a reference to a pointer for? Will a pointer to
> a pointer do?
>
> --
> A designer knows he has achieved perfection
> not when there is nothing left to add,
> but when there is nothing left to take away.
> * * * *Antoine de Saint-Exupéry



yeah pointer to pointer could be replacement for reference to pointer
in C . I was thinking that in C++ , we have pointer to reference . I
was thinking what could be the reason why Denis has not put reference
support in C ..
 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      07-02-2009
On 2009-07-02, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> On Jul 2, 12:26*pm, Nick Keighley <(E-Mail Removed)>
> wrote:
>> Then it becomes an "ask Dennis Richie question". He designed the
>> language and for some reason decided he didn't need references.
>> C is a very small and simple language that is close to the machine,
>> presumably references were just an abstraction that didn't seem
>> necessary (if, indeed, anything like references was even considered).

> yeah pointer to pointer could be replacement for reference to pointer
> in C . I was thinking that in C++ , we have pointer to reference . I
> was thinking what could be the reason why Denis has not put reference
> support in C ..


Pointers were in wide use when Dennis Richie created the C language. The
same was not true of references. I am not 100% sure in saying so; but, I
don't think any language was using references at the time. C++ was my
first exposure to references. Pointers predate references and references
where created as a direct answer to some of the problems that can be
created using pointers.

Whether Dennis Richie would have used references had they been more well
known is at this point academic.

That C has not adoped references is more clear. Many languages move
forward adding many new technologies to its core language. C++ itself has
done this and it is a very different language then it was when I first
started. The C community however, probably in a large account of us who
tend to dislike what C++ turned out to be, has chosen to stay closer to its
roots and recognize itself as a separate language then just as the
precursor to C++.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      07-02-2009
(E-Mail Removed) wrote:
....
> in C . I was thinking that in C++ , we have pointer to reference . I
> was thinking what could be the reason why Denis has not put reference
> support in C ..


Probably for the same reason he didn't put in overloaded functions,
templates, default argument values, or any of the other innovations
added to C++. Which is to say, he quite possibly didn't even think about
such ideas; if he did, he probably rejected them as adding unnecessary
complication to the language.

Except for the capabilities that they allow in combination with operator
overloading, C++ references are little more than syntactic sugar for
const pointers (not "pointers to const"). Since C doesn't include
operator overloading, there's not much point in adding references.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      07-02-2009
Tim Harig <(E-Mail Removed)> writes:

> On 2009-07-02, (E-Mail Removed) <(E-Mail Removed)> wrote:
>> [...] I was thinking that in C++ , we have pointer to reference . I
>> was thinking what could be the reason why Denis has not put reference
>> support in C ..

>
> Pointers were in wide use when Dennis Richie created the C language. The
> same was not true of references. I am not 100% sure in saying so; but, I
> don't think any language was using references at the time.


Algol-68 had a pretty well worked out notion of references by that
time. Ritchie notes that Algol-68 was a source of some of the
features of C and, in an aside, called pointers "references". To that
extent C does have references. What it does not have are any contexts
in which they are de-referenced automatically nor any in which a
reference is "picked up" automatically[1].

I like to think of C as having references (i.e. pointers) -- just not
auto-magic ones. I use the term auto-magic (in my mind) so as not to
confuse it with automatic which has its own meaning in C.

[1] Except of course for expressions of array or function type which
do get an automatic conversion to what C uses as a reference type.

--
Ben.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      07-02-2009
James Kuyper <(E-Mail Removed)> writes:

> (E-Mail Removed) wrote:
> ...
>> in C . I was thinking that in C++ , we have pointer to reference . I
>> was thinking what could be the reason why Denis has not put reference
>> support in C ..

>
> Probably for the same reason he didn't put in overloaded functions,
> templates, default argument values, or any of the other innovations
> added to C++. Which is to say, he quite possibly didn't even think
> about such ideas; if he did, he probably rejected them as adding
> unnecessary complication to the language.


Also, I think it is hard for today's students of computer science to
imagine how limited the original target for C was. Today, even a
compiler for a large language hardly impinges on a small laptop's
resources, but a PDP-11 with a maximum of 64k[1] would have struggled
with a modern C++ compiler, let along the poor 8k PDP-7 that was the
original development system. No doubt a compiler for a "big" language
could have been written for some of these later machines (Algol-68 did
come to the PDP-11 but some time after C) but it is unlikely that
doing so would have helped in the main purpose of C which was, as I
understand it, to re-write Unix in a high-level language.

[1] That is, of course, 64k per process -- the machines often had more
total RAM. Later models allowed 64k for data and a separate 64k for
code.

> Except for the capabilities that they allow in combination with
> operator overloading, C++ references are little more than syntactic
> sugar for const pointers (not "pointers to const"). Since C doesn't
> include operator overloading, there's not much point in adding
> references.


Agreed.

--
Ben.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      07-02-2009
Ben Bacarisse <(E-Mail Removed)> writes:
>features of C and, in an aside, called pointers "references". To that
>extent C does have references. What it does not have are any contexts
>in which they are de-referenced automatically nor any in which a
>reference is "picked up" automatically[1].


I could quote several parts of ISO/IEC 9899:1999 (E) to contradict this.
But to save time, here is just one:

Function references are resolved (»automatically«) in translation
phase 8:

»All external object and function references are resolved.«

ISO/IEC 9899:1999 (E), 5.1.1.2, 8



 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      07-02-2009
On 2009-07-02, Ben Bacarisse <(E-Mail Removed)> wrote:
> Tim Harig <(E-Mail Removed)> writes:
>> On 2009-07-02, (E-Mail Removed) <(E-Mail Removed)> wrote:
>>> [...] I was thinking that in C++ , we have pointer to reference . I
>>> was thinking what could be the reason why Denis has not put reference
>>> support in C ..

>> Pointers were in wide use when Dennis Richie created the C language. The
>> same was not true of references. I am not 100% sure in saying so; but, I
>> don't think any language was using references at the time.

> Algol-68 had a pretty well worked out notion of references by that
> time. Ritchie notes that Algol-68 was a source of some of the
> features of C and, in an aside, called pointers "references". To that


I guess that it might be important here to define what the "reference"
concept. From this:

http://rosettacode.org/wiki/Basic_po...tions#ALGOL_68

I gather that Algol-68 had something it called ref[s] that I would describe
as being something between C pointers and C++ references. They could be
re-assigned but they where incapable of doing pointer arithmetic. They
were implicitly dereferenced.
 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      07-02-2009
On 2009-07-02, Tim Harig <(E-Mail Removed)> wrote:
> On 2009-07-02, Ben Bacarisse <(E-Mail Removed)> wrote:
>> Tim Harig <(E-Mail Removed)> writes:
>>> On 2009-07-02, (E-Mail Removed) <(E-Mail Removed)> wrote:
>>>> [...] I was thinking that in C++ , we have pointer to reference . I
>>>> was thinking what could be the reason why Denis has not put reference
>>>> support in C ..
>>> Pointers were in wide use when Dennis Richie created the C language. The
>>> same was not true of references. I am not 100% sure in saying so; but, I
>>> don't think any language was using references at the time.

>> Algol-68 had a pretty well worked out notion of references by that
>> time. Ritchie notes that Algol-68 was a source of some of the
>> features of C and, in an aside, called pointers "references". To that

>
> I guess that it might be important here to define what the "reference"
> concept. From this:
>
> http://rosettacode.org/wiki/Basic_po...tions#ALGOL_68
>
> I gather that Algol-68 had something it called ref[s] that I would describe
> as being something between C pointers and C++ references. They could be
> re-assigned but they where incapable of doing pointer arithmetic. They
> were implicitly dereferenced.


Nevermind, I didn't notice the difference between = and :=.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Reference counting and API (const reference vs pointer oriented) mathieu C++ 8 08-31-2008 09:05 AM
reference and pointer-reference kasthurirangan.balaji@gmail.com C++ 4 12-24-2007 09:05 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM
Passing the value by reference is same as pointer by reference sam pal C++ 3 07-16-2003 09:14 PM



Advertisments