Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: convincing management to switch to Ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Skaller <skaller@m...>
Subject: Re: convincing management to switch to Ocaml
At 14:36 26/08/99 -0400, Stefan Monnier wrote:
>>>>>> "John" == John Skaller <skaller@maxtal.com.au> writes:
>> 	Wrong. C++ is type safe, provided you don't use casts.
>
>And several other C constructs like unions, arrays, varargs, manual
>memory management, ...

	Technically you are right for unions: however, I'd
consider using a union component 'equivalent to a cast'.
However, it isn't greppable like a cast, so you are right.

	C arrays are type safe, but the C conversion
of an array lvalue to a pointer to an array is not
type safe in the presence of classes when the array
type is a derived type, so you are also right there.

	Varargs macros are specially hacked up kinds
of casts, but again, you're technically correct.

	The case of stuffed up memory management
leading to a run time fault not really related to the type
system (just like indexing past the end of an array).

	There is, however, a special exception to this,
where you are right:

	Y *y = new X[n]; // upcast to base class
	del x; // hole in type system

but this is really the _same_ hole as before,
due to the conversion of an array to a pointer.

There is, in fact ANOTHER hole:

	Y *y = new X;
	del y;

which will fail if X doesn't have a virtual destructor.

------------------------

Given the list of things that are unsafe in C++,
I withdraw my claim that C++ is typesafe,
provided you don't use casts. The list of caveats
is much longer. [Ugh]


-------------------------------------------------------
John Skaller    email: skaller@maxtal.com.au
		http://www.maxtal.com.au/~skaller
		phone: 61-2-96600850
		snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia