Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!umd5!uvaarpa!virginia!scl From: scl@virginia.acc.virginia.edu (Steve Losen) Newsgroups: comp.sources.wanted Subject: Re: Pascal to C conversion Message-ID: <1019@virginia.acc.virginia.edu> Date: 1 Aug 88 16:31:52 GMT References: <336@sdrc.UUCP> <486@draken.nada.kth.se> <660@buengc.BU.EDU> Reply-To: scl@virginia.acc.Virginia.EDU (Steve Losen) Organization: University of Va., Charlottesville, VA Lines: 56 On the subject of Pascal to C conversion utilities: I know such beasts exist, but I don't know any by name. Offhand I can think of 3 areas to be very careful of when using such a program because Pascal has several features for which C has no obvious counterpart. 1) Up level references. In C, a function can only reference its own arguments, its own local variables, or global variables. In Pascal, a function or procedure can also reference the local variables and arguments of other subprograms. How does the translator handle the Pascal scope rules? The most correct way would be to pass extra arguments to the C functions. These extra arguments would be pointers to the variables being referenced. 2) Set operations: The translator will probably come with a library of set routines that the C programs call. 4) With statements: These cannot be handled with simple textual substitutions. For example, program test; type rec = record f1, f2 : integer; var a : array [1..10] of rec; i : integer; begin i := 5; with a[i] do begin for i := 1 to 10 do f1 := i; end end. According to the Pascal standard, a[i] is evaluated once at the beginning of the with statement. All the references to "f1" within the with statement refer to the same memory location (even though "i" changes). To get this right in C would require code like this: struct rec { int f1,f2;}; main() { struct rec a[10], *p; int i; i := 5; p = &a[i-1]; for(i=1; i<=10; i++) p->f1 = i; } I'm sure there are other areas to watch out for. Be sure your translator does the job correctly or at least admits where it fails. -- Steve Losen scl@virginia.edu University of Virginia Academic Computing Center