🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: C++ syntactic trap

#3976
From: J. Kanze
Date: Wed, 10 Apr 1996 11:20
39 lines
2500 bytes
In article <4kcrhk$aj1@hermes.acs.unt.edu> johnw@jove.acs.unt.edu (John
R. Williams) writes:

    [Concerning a warning for `new char( 10 )'...]
|> I agree that it is uusual to allocate a single object of a built-in type 
|> this way, but how do you propose to write this in such a way that such a 
|> warning would not be generated? All I can think of is to warn when *any* 
|> conversion occurs (this one looks pretty explicit to me), forcing you to 
|> write something like this:

|>   char *foo = new char(static_cast<char>(10));

|> (Actually this rule doesn't seem too bad if applied only to built-in 
|> types...)

Let's see:

    int*        pi = new int( static_cast< int >( 10 ) ) ;

Do you want the compiler to warn if you omit the static_cast (of int to
int)? 

I do not think that I have a single instance of allocation of an array
in any of my code.  Why should you make the most frequent case the most
difficult.  (And allocating a single int is not that infrequent.  You
might look at the implementation of counted_ptr in Barton and Nackman,
for example.  It is certainly more frequent than allocating an array of
int's, at least in well written C++ code.)
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle --
                            -- Beratung in industrieller Datenverarbeitung
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <KANZE.96Apr10111924@gabi.gabi-soft.fr>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <4k3q4p$lkd@syn.cs.cornell.edu> <4kcrhk$aj1@hermes.acs.unt.edu>

Show Full Headers
Complete Article Headers
From: kanze@gabi-soft.fr (J. Kanze)
Message-ID: <KANZE.96Apr10111924@gabi.gabi-soft.fr>
X-Original-Date: 10 Apr 1996 09:19:24 GMT
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 10 Apr 96 11:20:18 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: C++ syntactic trap
Organization: GABI Software, Sarl.
References: <4k3q4p$lkd@syn.cs.cornell.edu> <4kcrhk$aj1@hermes.acs.unt.edu>
In-Reply-To: johnw@jove.acs.unt.edu's message of 09 Apr 1996 09:59:37 PDT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMWuZeeEDnX0m9pzZAQGp6gF9FTRRzKNjaQDcCSyx5MxUUkU4gK+UwlQ8
 PCoLabRUVxGZcWdxBvXaT2Wx6UzgGoxp
 =vQPl