Reference to Pointer

Discussion in 'C Programming' started by bansalvikrant@gmail.com, Jul 2, 2009.

  1. Guest

    Hi,

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

    Thanks
    Vikrant
     
    , Jul 2, 2009
    #1
    1. Advertising

  2. On 2 July, 07:55, "" <>
    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
     
    Nick Keighley, Jul 2, 2009
    #2
    1. Advertising

  3. Guest

    On Jul 2, 12:26 pm, Nick Keighley <>
    wrote:
    > On 2 July, 07:55, "" <>
    > 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 ..
     
    , Jul 2, 2009
    #3
  4. Tim Harig Guest

    On 2009-07-02, <> wrote:
    > On Jul 2, 12:26 pm, Nick Keighley <>
    > 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++.
     
    Tim Harig, Jul 2, 2009
    #4
  5. James Kuyper Guest

    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.
     
    James Kuyper, Jul 2, 2009
    #5
  6. Tim Harig <> writes:

    > On 2009-07-02, <> 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.
     
    Ben Bacarisse, Jul 2, 2009
    #6
  7. James Kuyper <> writes:

    > 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.
     
    Ben Bacarisse, Jul 2, 2009
    #7
  8. Stefan Ram Guest

    Ben Bacarisse <> 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
     
    Stefan Ram, Jul 2, 2009
    #8
  9. Tim Harig Guest

    On 2009-07-02, Ben Bacarisse <> wrote:
    > Tim Harig <> writes:
    >> On 2009-07-02, <> 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_pointer_and_reference_operations#ALGOL_68

    I gather that Algol-68 had something it called ref 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.
     
    Tim Harig, Jul 2, 2009
    #9
  10. Tim Harig Guest

    On 2009-07-02, Tim Harig <> wrote:
    > On 2009-07-02, Ben Bacarisse <> wrote:
    >> Tim Harig <> writes:
    >>> On 2009-07-02, <> 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_pointer_and_reference_operations#ALGOL_68
    >
    > I gather that Algol-68 had something it called ref 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 :=.
     
    Tim Harig, Jul 2, 2009
    #10
  11. James Kuyper <> wrote:
    > 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++.


    Pass by reference was a stable of FORTRAN (et al) long before
    C and 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.


    Ironic then that many language designers in the era dismissed
    pointers because they added unnecessary complexity to
    programming.

    --
    Peter
     
    Peter Nilsson, Jul 3, 2009
    #11
  12. James Kuyper Guest

    Peter Nilsson wrote:
    > James Kuyper <> wrote:
    >> 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++.

    >
    > Pass by reference was a stable of FORTRAN (et al) long before
    > C and 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.

    >
    > Ironic then that many language designers in the era dismissed
    > pointers because they added unnecessary complexity to
    > programming.


    K&R decided that passing by value would be the norm in C, and that
    pointers passed by value would be used to serve the same purpose as pass
    by reference in those other languages. Having made those decisions,
    adding a reference type on top of pass-by-value gets complicated; just
    take a look at C++ for an example of the complications that can ensue.
     
    James Kuyper, Jul 4, 2009
    #12
  13. mecej4 Guest

    "Tim Harig" <> wrote in message
    news:qP%2m.3574$...
    | On 2009-07-02, <> wrote:
    | > On Jul 2, 12:26 pm, Nick Keighley <>
    | > 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.

    Whether references were called "references or not", there were languages
    that provided something similar. PL/I, for example, provided "based
    variables". You could set a pointer to point to a string, for example.
    Thereafter, everytime the pointer value was changed, the based variable
    would acquire a new value, without any explicit deferencing being done as in
    C. Here is an example:

    TestProg: PROC OPTIONS(MAIN);

    DCL Str char(20) init ("abcdefghijklmnopqrst");

    DCL C char based (p),p pointer;

    DCL i FIXED BIN(31);

    p=addr(Str);

    DO i=1 to 20;

    put edit(C)(A(1)); p+=1;

    end;

    put skip;

    END TestProg;

    | 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++.
     
    mecej4, Jul 8, 2009
    #13
  14. On Thu, 2 Jul 2009 23:13:52 -0700 (PDT), Peter Nilsson
    <> wrote:

    > James Kuyper <> wrote:
    > > 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++.

    >
    > Pass by reference was a stable of FORTRAN (et al) long before
    > C and C++.
    >

    (You mean staple.) It wasn't fully standard in FORTRAN but was very
    common; it was standard in COBOL and PL/I, and explicit in Pascal.
    As noted elsethread a68 had generalized to both parameters and locals
    (but reseatable, unlike C++); and PL/I had BASED(p) which functioned
    the same way, as did 'Cray pointers' in many FORTRAN implementations
    (but not the standard).

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

    >

    But a68 and PL/I were famed(?) as 'kitchen-sink' languages, containing
    so much cruft they were hard to implement, especially as noted
    elsethread on smaller (= affordable) minicomputers of the day.
     
    David Thompson, Jul 12, 2009
    #14
  15. OT Nit:
    On Thu, 02 Jul 2009 16:11:32 +0100, Ben Bacarisse
    <> wrote:

    > James Kuyper <> writes:
    >
    > > 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. <snip>
    >
    > [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.
    >

    Or less. Lower-end -11 models did not have memory mapping so you had
    at most 56KB, including both OS or equivalent such as fixed drivers
    plus user; and in its early days (when C was created) semiconductor
    memory was quite expensive, as was core, and machines were commonly
    furnished with only 32KB, 24KB, even 16KB. (Which 'partial' filling
    UNIBUS and later Q-BUS could handle correctly.) Although you would not
    by choice use those machines for program development.

    And even with mapping, physical memory on 18-bit busses (until IIRC
    about '76 or '77) was maximum 248K, not much more than the first Apple
    Mac and IBM PC.

    FWIW the -7 could directly address 8K *words* of 18 bits. And it was
    the original machine for Unix, but using B; C started on the -11.
     
    David Thompson, Jul 12, 2009
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sam pal
    Replies:
    3
    Views:
    591
    E. Robert Tisdale
    Jul 16, 2003
  2. Replies:
    10
    Views:
    740
    Chris Torek
    Feb 4, 2005
  3. Replies:
    4
    Views:
    410
    Andre Kostur
    Dec 24, 2007
  4. mathieu
    Replies:
    8
    Views:
    531
    Juha Nieminen
    Aug 31, 2008
  5. A
    Replies:
    7
    Views:
    656
Loading...

Share This Page