🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: typedef not strong

#3414
From: Harlan Messinger
Date: Thu, 22 Feb 1996 21:33
49 lines
2807 bytes
Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
: rpayne@rainbow.rmii.com (Robert Payne) writes:
: 
: >Why has C++ stayed with the weak typedef?  It has always seemed to
: >me that it should provide a new type and not just a synomym.  Some
: >lints check for strong typing but I haven't found a compiler that 
: >will enforce it.  I know this must have been debated at some point
: >but I didn't find it in a FAQ.  Could someone please enlighten me?
: 
: If typedef were to create a new type, what operations would be allowed
: on the new type?
: 
: I think that changing the meaning of `typedef' would be a bad idea.
: It might make sense to propose a new construct, say `newtypedef', that
: did something different, but C++ already has a way to create new types
: (`class'), and it is not at all clear that adding a new way would be
: worth the additional complexity.


I see two issues at odds here, and a desire to satisfy them both with one 
construct.

One issue is type safety in function calls. You might have

	typedef double DOLLARS;
	typedef double INTEREST_RATE;

and want to define a function declared as

	DOLLARS PresentValue(DOLLARS futureValue, 
		INTEREST_RATE rate, int YEARS);

that will keep the user from accidentally swapping the money and interest 
arguments when coding a call to the function.

On the other hand, within functions that use these types, you might want
all the ordinary mathematical functions to apply as usual to the raw
values underneath. The function call has already guaranteed that the set
of arguments given has types that are meaningful given the function's 
purpose. Now we want to take these arguments for what they really 
are--doubles--and apply normal arithmetic to them with no headaches.


[ To submit articles: Try just posting with your newsreader.
		      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: <4gimon$317@clarknet.clark.net>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <4g5sm4$dtt@natasha.rmii.com> <4g8vdo$igt@mulga.cs.mu.OZ.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: gusty@clark.net (Harlan Messinger)
Newsgroups: comp.std.c++
Subject: Re: typedef not strong
Date: 22 Feb 1996 21:33:36 GMT
Organization: Clark Internet Services, Inc., Ellicott City, MD USA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4gimon$317@clarknet.clark.net>
References: <4g5sm4$dtt@natasha.rmii.com> <4g8vdo$igt@mulga.cs.mu.OZ.AU>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Nntp-Posting-Host: explorer.clark.net
X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
X-Lines: 42
Content-Length: 1743
Originator: clamage@taumet