Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!uflorida!gatech!prism!sun13!gw.scri.fsu.edu!pepke From: pepke@gw.scri.fsu.edu (Eric Pepke) Newsgroups: comp.sys.mac.programmer Subject: Re: From Pascal to C without a hitch ? Message-ID: <1158@sun13.scri.fsu.edu> Date: 17 Oct 90 20:48:56 GMT Sender: news@sun13.scri.fsu.edu Organization: Florida State University, but I don't speak for them Lines: 71 References:<1990Oct17.151226.2449@fennel.cc.uwa.oz.au> Pascal and C are almost identical. This no doubt explains why the flame wars over which is "better" and why are so bitter and vitriolic. Nothing starts a holy war like a tiny difference in interpretation of doctrine. They are almost identical because they started off nearly so, as ALGOL-type block-structured procedural languages. Also, over the years, people have been working to put C-like features such as loop breaks and type casts into PASCAL and PASCAL-like features such as strong typing in functions into C. The remaining differences tend to be mostly syntactic or obscure and avoidable. It is too bad you haven't yet had languages like APL, SNOBOL, PROLOG, and LISP, which would help you appreciate just how really small the difference is. But you can still get the same result by thinking about BASIC all the time. The following is a list of about 90% of the real differences between PASCAL and C. In most cases there's, near enough, a one-to-one correspondence, in others there is quite a bit of difference in the details. Warning! The mere possesion of such a list can still get you burned as a heretic in many parts of the world. On the other hand, it might help you get your job done. This list, plus a copy of Kernhigan & Ritchie, should enable you to convert sample programs from PASCAL to C, and after a few tries, you will know C. Pascal C ------ - BEGIN ... END { ... } IF foo THEN bar [ ELSE moo ] IF (foo) bar; [ ELSE moo ] ; between statements ; at end of statement := = = == <> != NOT ! PROGRAM ... END . main() { ... } RECORD struct variant RECORD union REAL float, double INTEGER short, long, int WHILE foo DO bar while (foo) bar REPEAT foo UNTIL bar do { foo } while (!bar) bork; (proc or function call) bork(); FUNCTION toad : type; type toad() toad := 3; return 3; CASE foo of switch (foo) 1: case 1: (remember break at end) ARRAY glop[0..9] of integer int glop[10] TYPE section typedef foo . bar foo . bar foo ^. bar foo -> bar foo^ *foo WITH no such animal OTHERWISE (nonstandard) default: declared, numeric labels undeclared, nonnumeric labels FOR k := 0 TO 9 DO bork for (k = 0; k < 10; ++k) bork CYCLE (nonstandard) continue LEAVE (nonstandard) break a AND b (a and b evaluated first) a && b (b only evaluated if a) a OR b (a and b evaluated first) a || b (b only evaluated if not a) nested procedures and functions no such animal CHAR is not a number, use ORD() char is a number as well as a character type(foo) (nonstandard) (type) foo Eric Pepke INTERNET: pepke@gw.scri.fsu.edu Supercomputer Computations Research Institute MFENET: pepke@fsu Florida State University SPAN: scri::pepke Tallahassee, FL 32306-4052 BITNET: pepke@fsu Disclaimer: My employers seldom even LISTEN to my opinions. Meta-disclaimer: Any society that needs disclaimers has too many lawyers.