Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!sun-barr!newstop!texsun!pollux!ti-csl!m2!gateley From: gateley@m2.csc.ti.com (John Gateley) Newsgroups: comp.lang.c Subject: Re: Pascal to C (and vice versa) Message-ID: <95516@ti-csl.csc.ti.com> Date: 24 Oct 89 04:34:28 GMT References: <5164@uhccux.uhcc.hawaii.edu> <4640@mentor.cc.purdue.edu> Sender: news@ti-csl.csc.ti.com Reply-To: gateley@m2.UUCP (John Gateley) Organization: TI Computer Science Center, Dallas Lines: 54 In article <4640@mentor.cc.purdue.edu> acu@mentor.cc.purdue.edu (Floyd McWilliams) writes: >In article <5164@uhccux.uhcc.hawaii.edu> dillon@uhccux.uhcc.hawaii.edu > (Ian Dillon) writes: >>I'm looking for a Pascal to C (and back again) conversion program. > I'd like to see how a C-to-Pascal conversion program would handle this: > int i, *pi; > pi = &i; Basically, what you do is declare a huge array of integers; this represents `memory'. Now, an address is an index into the array. Whats that? You wanted it efficient too? :^) > Or this: > int *A; > A = (int *) malloc((unsigned) (sizeof(int) * 20)); > A[10] = 5; Same process, except you have to write malloc in pascal. > Or, for that matter, how a Pascal-to-C converter would take: > var > X : set of char; > X := ['a','b','c']; > if 'a' in X then > X := X + 'A' > else > X := X * ['b','c']; This one can be done easily. A set can be represented as a bit vector (also known as an integer), of appropriate lenght. So you get int x[16] /* you need 256 bits */ for(i=0;i<16;i++) x[i]=0; /* 'a' is 97 */ x[6]:=x[6] && 1 /* or &, I dunno, I dont speak C */ and so on, you get the idea. > Now I know all these conversions CAN be done (since C and Pascal >are Turing-equivalent). But can they be done by currently available >programs? Sure, you can write a program to do it. The question really is "can they be done so the output is useful". In the first case (addresses), Pascal doesn't have a mechanism for dealing with them easily, you might be able to fake them with pointers, or go with the approach I suggested above. In any case, there is an overhead associated with them. In the second case (Pascal Sets in C), the output is likely to be highly unreadable. I took a lot of shortcuts above, the code which would be generated automatically would be grosser. John gateley@m2.csc.ti.com