Xref: utzoo comp.lang.c++:12348 comp.lang.objective-c:205 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!crackers!m2c!umvlsi!dime!connolly From: connolly@livy.cs.umass.edu (Christopher Connolly) Newsgroups: comp.lang.c++,comp.lang.objective-c Subject: Re: Static typing, OOP efficiency, and programmer error Message-ID: <28148@dime.cs.umass.edu> Date: 19 Mar 91 20:23:04 GMT References: <27CE9C05.4F64@tct.uucp> <1860@news.tcs.com> <47199@nigel.ee.udel.edu> <27E17FD1.7241@tct.uucp> Sender: news@dime.cs.umass.edu Reply-To: connolly@livy.cs.umass.edu (Christopher Ian Connolly) Followup-To: comp.lang.c++ Organization: University of Massachusetts, Amherst Lines: 61 In article <27E17FD1.7241@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: >According to carroll@cis.udel.edu (Mark Carroll): >>... by using dataflow analysis to bind statically whenever possible, >>any of the errors that could be caught statically in C++ could be caught >>statically in Objective-C. > >I think that the above statement is incorrect. The C++ language is >incapable of compiling a program that results in an object receiving a >message it can't handle. I don't know much about Objective-C, so I can't say anything about Mark Carroll's statement. On the other hand, the AT&T version 2.1 C++ translator will successfully compile this program: ///////////////////////////////////////////////////////////////////// #include struct junk { int foo; virtual int barf() { cout << "Bandaged Knuckles.\n" << flush; return(foo); } }; struct eat_me { int foo; }; main() { junk* fool_me_once; eat_me* fool_me_twice; void* bar; cout << "Let the festivities begin.\n"; fool_me_once = new junk; fool_me_once->foo = 1; fool_me_once->barf(); fool_me_twice = new eat_me; fool_me_twice->foo = 2; bar = (void*) fool_me_twice; fool_me_once = (junk*) bar; fool_me_once->barf(); } ///////////////////////////////////////////////////////////////////// The resulting executable (a.out) prints this: sunbeam% a.out Let the festivities begin. Bandaged Knuckles. Segmentation fault (core dumped) sunbeam% This is a case where an object is "receiving a message it can't handle", the result being a segmentation fault. Nicht wahr? >I am not willing to sacrifice type safety for elegance. I'd like both, with an order of magnitude to go, please. -C. Connolly