Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!crdgw1!underdog!shane From: shane@underdog.crd.ge.com (Randall H. Shane) Newsgroups: alt.religion.computers Subject: Re: Shoulds arrays start at zero or one? Message-ID: <4832@crdgw1.crd.ge.com> Date: 17 Jan 90 19:53:08 GMT References: <252@usblues.UUCP> <1990Jan16.173034.25686@murdoch.acc.Virginia.EDU> <4822@crdgw1.crd.ge.com> <1990Jan17.044003.2039@world.std.com> Sender: news@crdgw1.crd.ge.com Reply-To: shane@underdog.crd.ge.com (Randall H. Shane) Distribution: na Organization: GE Corporate R&D Center Lines: 82 In article <1990Jan17.044003.2039@world.std.com> bzs@world.std.com (Barry Shein) writes: ] From: shane@underdog.crd.ge.com (Randall H. Shane) ] >Of course, the performance implications of 'stoopid' compilers are ] >enormous, and often not told to USENET posters. Stupid compilers ] >exist for most, if not all languages, and the mere existence of stupid ] >compilers is hardly a reason to slam a computer language. Intelligent ] >Pascal compilers, while enforcing the semantics of var and non-var ] >parameters in the program text, for efficiency's sake pass large structures ] >such as arrays by reference in both cases. This efficient implementation ] >is not a contradiction of the programmer's intent, let us note.... ] Over the past decade or so, whenever I get into an argument about how ] dumb Pascal is, the Pascal proponent always informs me of wonderous ] Pascal compilers which fix the complaint at hand. Please, don't count me as a Pascal 'proponent' -- that overstates the situation greatly. I merely stated an area where I thought Pascal, and by implication, other languages such as Ada with similar semantics in that area, was superior to C. Saying that C isn't perfect hardly makes be a Pascal proponent -- I haven't programmed in Pascal in three years. ] Everyone knows that Pascal has no initialization syntax. So one is ] told to just put a lot of assignments in the mainline which has ] roughly the same effect (roughly because the errors can be different, ] but we'll leave that be.) At least one Pascal compiler I know of (UBC Pascal for the MTS operating system) had extensions to perform proper initialization, though I personally found the syntax EXTREMELY clumsy, and almost not worth it. The lack of a good initialization syntax is a severe disadvantage in Pascal, I agree. ] If I point out that this can exact a heavy start-up cost (particularly ] if setting array elements) on every run of the program I am often ] told: Well, that's just because of stupid compilers, good Pascal ] compilers recognize these and turn them into the same as C (load-time ] initialization.) Ok, makes sense, I know compiler internals well ] enough to know that's possible or at least plausible. ] One day, after such an argument, I wrote a simple piece of Pascal code ] and compiled it on several compilers: Unix/Pascal, VMS/Pascal, ] IBM370/Pascal/VS, (some other 370 Pascal we had), Greenhill, a few ] others. ] Examining the generated code in each case revealed that not one of ] them performed this "optimization", they all did some form of load and ] store as regular code in the routine. When confronted with this the ] Pascal proponent could not name a compiler known to perform the ] claimed optimization and admitted that every one he had used was in my ] test suite. Swell. I'd assume that the reason for this is that much more effort overall is invested in C compilers, and in optimization in C compilers, than in Pascal compilers -- which is reasonable, since C is greatly more used than Pascal. ] I've seen similar claims for Pascal compilers, including a claim that ] one should handle variable length strings (something Pascal is ] incapable of) by putting them into single-character linked-lists and ] the compiler will fix that to be a lot like C (no joke.) THAT claim is a good example of blind ignorance -- I'll have to file that one..... ] So, I ask, exactly which Pascal compiler performs the optimization of ] hunting down call by value parameters and changing them to call by ] reference, specifically. If you can produce some sample generated code ] all the better. Well, this is all from memory, since I no longer have access to a MTS machine, but I believe that it actually converted all parameters to reference parameters in the compiled code. I can't produce the generated code to PROVE this, but if I have a chance in the next few weeks, I'll look up the UBC manual if I still have a copy and check this out....... Whether or not I can find a compiler that performs the optimization, I'm sure of my main point (which I believe is more than a personal prejudice, but I'm not willing to claim as an Universal Truth :-) which is that the Pascal style syntax for var-style parameters is preferable and superior to C's syntax. -- Randall Shane [shane@disney.crd.ge.com] "C combines the power and flexibility of assembly language with the ease of use of assembly language."