Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!image.soe.clarkson.edu!news From: cline@cheetah.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c++ Subject: Re: porting tips for c++ Message-ID: Date: 9 Aug 90 17:58:54 GMT References: <1990Aug6.133901.25745@swbatl.sbc.com> <943@tcs.tcs.com> Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Organization: (I don't speak for the) ECE Dept, Clarkson Univ, Potsdam, NY Lines: 62 In-reply-to: gwu@nujoizey.tcs.com's message of 8 Aug 90 00:32:36 GMT In article <943@tcs.tcs.com> gwu@nujoizey.tcs.com (George Wu) writes: >... This memorandum summarizes the necessary procedures used to switch from >GNU's C++ compiler to Sun's C++ compiler (AT&T Cfront 2.0).... Summary: Most of the things cfront wouldn't accept are in fact wrong C++. > o Constructors cannot have default argument values. The compiler does > not always complain about this problem. Consider the following > example: > class C { > public: > C(int x = 0); > C(int x, int y = 0); > }; A good reason that cfront wouldn't accept this is that it's ambiguous! Ex: C c(10); //Should `c' be constructed with C::C(int) or with C::C(int,int=0)? > o Default argument values can only be declared in one place. Declare > default argument values in the class definition, not in the function > definition. This is not a bug in cfront: ``A default argument cannot be redefined by a later declaration (not even to the same value).'' [ARM, p.141]. However ``early versions of C++ allowed multiple default initializers for a single argument, as long as they were equivalent. Defining "equivalent" proved problematic, however.'' [ARM, p.144]. Note however that subsequent declarations can *add* default args in a right-to-left fashion... > o Values of type void* can only be assigned to variables of type void*. > The C++ permits any pointer value to be automatically cast to a > void* where necessary, but this relationship is not symmetrical. > Expressions of type void* must therefore be explicitly cast to the > appropriate pointer type. For example, given char* s and void* p, > s = p becomes s = (char *) p. Again cfront is correct (I'd be surprised if GNU C++ accepted this either!). ANSI C allows automatic coersion from void* to anything*, but this is a BIG hole in the type system, since the anything* to void* cast (which is allowed in both C and C++) would allow any pointer type to be silently coersed to any other pointer type by going through void*. > o The type of a pointer to a function includes the function argument > types, ie. the function prototyping must also be specified when > using function pointer. ^^^^^-- I assume you mean `declaring' -- M.Cline Yes, this too is correct. The type of a pointer-to-function not only includes the number and types of the function's parameters, it also has the function's return value. Marshall Cline -- ============================================================================== Marshall Cline / Asst.Prof / ECE Dept / Clarkson Univ / Potsdam, NY 13676 cline@sun.soe.clarkson.edu / Bitnet:BH0W@CLUTX / uunet!clutx.clarkson.edu!bh0w Voice: 315-268-3868 / Secretary: 315-268-6511 / FAX: 315-268-7600 Career search in progress; ECE faculty; research oriented; will send vita. PS: If your company is interested in on-site C++/OOD training, drop me a line! ==============================================================================