Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!mailrus!ncar!tank!eecae!cps3xx!rang From: rang@cpsin3.cps.msu.edu (Anton Rang) Newsgroups: comp.lang.pascal Subject: Re: C Ternary Conditional Expression? (Pascal vs C) Message-ID: <3275@cps3xx.UUCP> Date: 4 Jun 89 03:03:58 GMT References: <950025@hpclcdb.HP.COM> <50600002@uxe.cso.uiuc.edu> Sender: usenet@cps3xx.UUCP Reply-To: rang@cpswh.cps.msu.edu (Anton Rang) Organization: Michigan State University, Computer Science Dept. Lines: 83 In-reply-to: mcdonald@uxe.cso.uiuc.edu's message of 2 Jun 89 20:37:00 GMT In article <50600002@uxe.cso.uiuc.edu> mcdonald@uxe.cso.uiuc.edu writes: I have never really programmed in Pascal; I went from Fortran and assembler to C. It took me about 5 minutes to learn and understand the syntax and importance of such C constructs as a = x++; a += x; if( a = y) q = p++; These don't add any power to the language. I will agree that they are shorter than the equivalent Pascal code, though. C's pointer declaration syntax is indeed a disaster area, but the utility is enormous. Virtually anything can be written in straightforward C, including OS code, device drivers, and interrupt handlers. True enough. C is basically assembly language dressed up, so you can work at the bare-bones machine level. Pascal doesn't let you do this, at least if you adhere to the ISO standard. Then again, device drivers and interrupt handlers are not exactly portable, so it doesn't hurt any to use your favorite extensions when programming these in Pascal. I've written OS (kernel mode) code using Pascal before, on a VAX. The code is about 30% shorter in Pascal than its C equivalent (which I also wrote out for fun, and to give to a friend who didn't have the Pascal compiler). The reason is that Pascal has string handling and variable-length (conformant) arrays built in; since C has the simplest (most naive) string handling, it's lots more work to interface to other languages which support string descriptors, for instance. The best way to understand the difference between C and PAscal is to realize that C was designed to implement an entire operating system from the ground up, and Pascal was designed as a teaching language, essentially a toy. C is glorified assembly language (adding control structures and an easier method of structure handling). Pascal is designed to make programming in it easier, though less flexible unless you use extensions. The extensions aren't built in, because they vary a LOT from machine to machine. (Just out of curiousity, are there any C implementations on Lisp machines? Pascal runs great on a Symbolics, getting along happily with Lisp and the OS.) A[nd] so it is today: C is for secure grown-ups, Pascal is for the insecure. C is for people who need to write either semi-portable code under UNIX, or for people who dislike the convolutions needed to do odd things (like treat a string as a floating-point number, or an integer as a pointer) in Pascal. Pascal is for people who prefer programming in a more structured manner. It catches many of the errors which the programmer can make. (I believe there was a discussion of this on comp.misc--features which were desirable within a language to aid in debugging.) It has strong type checking. It allows both pass-by-value and pass-by-reference. It also allows nested procedures; this makes it much easier to control the visibility of variables, and makes it easier to work on large projects. (This is a serious omission in C.) Test for the Pascal lover: translate all of Unix into (legal, ISO standard, with NO extensions) Pascal. Well, it would be easier if you'd translate it all into C first. Seriously, this would be tough. Then again, if you can translate it into ANSI C, I can translate it into ISO Pascal. Why? Because the *only* "feature" of C which is "missing" in Pascal is the lack of type checking. Pascal allows variant records to handle this. It would be longer than the equivalent C, but both languages let you do the same things--neither one is more powerful than the other. However, it requires some NASTY convolutions to translate Pascal with nested procedures and functions into C. I program in both C and Pascal, depending on the system I'm using. VAXen work much better with Pascal (and have the best implementation I've used). I use C on my Mac at the moment, but will be picking up Pascal this summer and may start using that instead. On UNIX systems, I use C (when I can't avoid programming.) Anton +---------------------------+------------------------+ | Anton Rang (grad student) | "VMS Forever!" | | Michigan State University | rang@cpswh.cps.msu.edu | +---------------------------+------------------------+