Path: utzoo!attcan!uunet!mcvax!cernvax!ethz!iis!heiser From: heiser@iis.UUCP (Gernot Heiser) Newsgroups: comp.lang.modula2 Subject: Re: Re: C++ vs. Modula2 Message-ID: <739@jupiter.iis.UUCP> Date: 19 Jan 89 19:31:52 GMT References: Reply-To: heiser@iis.ethz.ch (Gernot Heiser) Organization: Integrated Systems Lab., ETH Zuerich Lines: 75 Summary: Expires: In article Info-Modula2 Distribution List writes: > >quoth Gernot Heiser : [ ... ] >As was recently observed in the info-pascal mailing list, optimization -> >conditional compilation. Consider: [ example deleted] >All but the most inanely STUPID of compilers will completely eliminate the >unreachable code. This has already been clarified by other posters. >>Both have serious deficiencies here. The most serious one is probably the >>impossibility to pass multi dimensional arrays of vaying size to subprograms. >>Linearizing your matrices to be able to pass them to subprograms is a step back >>towards assembler code. [ ... ] >I don't understand how it is 'impossible' to pass such arrays in C. I may >not be cognizant of changes made by the ANSI standard in this regard, but >each dimensional component of a C array being merely a pointer, one may >readily pass any array of any structural characteristic, to a 'subprogram'. >It is however, necessary to pass explicit information regarding the run-time >structural characteristics of such a data object, in order to prevent >inappropriate memory accesses. Of course you can pass multi dimensional arrays to C procedures, but there are no multi-dimensional open array parameters. Consider SUBROUTINE sub (N,A) INTEGER N REAL A(N,*) i.e. a formal array where the size of more than one dimension is variable. Both Modula-2 and C only allow one dimension to be "open". (If anybody knows of an elegant means (NOT a hack) to do this in C++ I'd be interested to hear about it. >Nor do I understand what is unreal about >C's 'for'. It is a powerful generalization (within it's limited domain) >of the BASIC/Pascal/Modula, etc. 'for'. I'd like to know what objections >you have to the character of the C 'for', please. Some call it powerful, others call it messy. First of all it is not a generalization of BASIC/Pascal/Modula, its a leftover of one of ALGOL/60's worst features. C's 'for' is really a 'while' with an initialization clause and a designated spot that may contain an incrementation clause. What I consider a "real" 'for' (as opposed to the while/repeat/loop family) is a construct that executes a specific number ot times, the iteration count being determined BEFORE the processing of the body starts. This is what is really needed most of the time in numerical programs. The other cases are exactly what while/repeat/ loop constructs are for. >>....Modula provides no means to switch between single >>and double precision depending on the hardware (e.g. using single precision on >>>= 48 bit hardware, double precision otherwise). C makes that easy using >>#define. > >Again, conditional compilation... If you ever see anything like IF this_is_a_CRAY THEN VAR number: REAL; ELSE VAR number: LONG REAL; END; then it's certainly not Modula-2 (nor a language I could imagine to be particularly fond of). >I hope that my comments will be construed constructively and prove sufficiently >non-trivial to provoke some rejoinder. you asked for it :-) -- Gernot Heiser Phone: +41 1/256 23 48 Integrated Systems Laboratory CSNET/ARPA: heiser%iis.ethz.ch@relay.cs.net ETH Zuerich UUCP (new): heiser@iis.uucp CH-8092 Zuerich, Switzerland UUCP (old): {uunet,mcvax,...}!iis!heiser