🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3609

Re: Some ideas about C++ and a question

#3609
From: Zefram
Date: Thu, 07 Mar 1996 15:44
59 lines
2889 bytes
Valentin Bonnard  <bonnardv@pratique.fr> wrote:
>1) String literals
>~~~~~~~~~~~~~~~~~~
>String literals should be const char* instead of char* (if it is not
>already the case).

Actually they're char[], which in practice is almost always decayed to
char*.  The reason they aren't char const[] is that a lot of existing C
code does things like `char *foo="bar";', because const didn't exist in
K&R C.

In my opinion, C++ code tends to use const correctly much more than C
code does.  (I personally always write const correctness into my C
code, but a lot of people do not, quite apart from the matter of
existing code.)  It would therefore probably not be disastrous to have
string literals have type char const[] in C++, though it would be in
C.  Maybe in the next round of standardisation?

>2) Placement operators
>~~~~~~~~~~~~~~~~~~~~~~
>class Object {
>        void    operator+ // or / or whatever
>                         (Object& result, const Object& b) const;
>        void    operator* (Object& result) const;
>        Object  operator* (const Object& result) const; // old one
>}
>
>should be called respectively by:
>a = b + c;
[...]

GCC has a better syntax for this, using a declaration "return result"
between the parameter list and the function body.  The function has a
return value in the usual way, but if it doesn't contain a return
statement with a value then the object in the return declaration is
returned.

>4) Conversion of Type** to const Type**
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>It's ok, this is an error; but why cannot Type** be converted to const Type* 
>const* ?

It can in C++, but not in C.  It is in fact safe, but the discovery of
the problem with converting T** to T const** led to the present C rule,
which was cast in stone (figuratively) before the C++ rule was
developed.

-zefram
-- 
Andrew Main <zefram@dcs.warwick.ac.uk>


[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID: <1996Mar7.023538.19136@dcs.warwick.ac.uk>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <4h9se5$m2n@s3.iway.fr>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: A.Main@dcs.warwick.ac.uk (Zefram)
Newsgroups: comp.std.c++
Subject: Re: Some ideas about C++ and a question
Date: 7 Mar 1996 15:44:48 GMT
Organization: Department of Computer Science, Warwick University, England
Sender: news@dcs.warwick.ac.uk (Network News)
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <1996Mar7.023538.19136@dcs.warwick.ac.uk>
References: <4h9se5$m2n@s3.iway.fr>
NNTP-Posting-Host: taumet.eng.sun.com
X-Nntp-Posting-Host: stone
X-Stardate: [-31]7160.43
X-Us-Congress: Moronic fuckers
Originator: clamage@taumet