🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9280

Re: references - C++

#9280
From: karl
Date: Tue, 09 Sep 1986 17:53
30 lines
2132 bytes
alice!bs (Bjarne Stroustrup) writes:
>Karl W. Z. Heuer writes:
>>BMS-AT!stuart writes:
>>>[re the declaration of reference types "foo(char &c)"]
>>>I don't like this.  It violates the nice consistent way ...
>>
>>I am also somewhat uneasy about calling it "char &c".  The consistent way to
>>declare it would be "char *&c", since you have to write "&c" to get ahold of
>>the "char *" object you are really using.
>
>The notation T& is the C++ notation for a reference to an object of type T.
>        char& c;        declares c to be a reference to a char
>        char*& r;       declares r to be a reference to a char*
>& is a declarator operator exactly like *

Understood.  The point was that (in C) a declaration like "int *(*f[])();"
asserts that "*(*f[])()" is an int (so one can work backwards to show that
f must be an array of pointers to functions returning pointers to int).  The
use of "&" for the reference declarator operator breaks this heuristic; now
"char &c" declares a reference to a "char", so "&c" is of type "char *".  If
the operator were spelled "*&" instead, then "char *&c" would denote a
reference to a "char", "char **&r" would be a reference to a "char *", and
"char &x" would be illegal.  Since "**&r" really does give you an object of
type "char", this notation might be easier to interpret.  (I suspect that
stuart was (incorrectly) applying this heuristic, and it led him to believe
that "&c" was somehow an object of type "char".)

Karl W. Z. Heuer (ima!haddock!karl; karl@haddock.isc.com)
This isn't C (not even ANSI proposed), so let's move it to net.lang.c++, OK?
Technical Details
Message-ID: <86900050@haddock>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karl
References: <6023@alice.uUCp>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karl
From: karl@haddock
Newsgroups: net.lang.c
Subject: Re: references - C++
Message-ID: <86900050@haddock>
Date: Tue, 9-Sep-86 13:53:00 EDT
Article-I.D.: haddock.86900050
Posted: Tue Sep  9 13:53:00 1986
Date-Received: Tue, 9-Sep-86 21:18:08 EDT
References: <6023@alice.uUCp>
Lines: 30
Nf-ID: #R:alice.uUCp:6023:haddock:86900050:000:1602
Nf-From: haddock!karl    Sep  9 13:53:00 1986