Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!bu-cs!madd From: madd@bu-cs.BU.EDU (Jim Frost) Newsgroups: comp.sys.ibm.pc Subject: Oddities in Turbo Pascal 4.0 Message-ID: <23497@bu-cs.BU.EDU> Date: 25 Jun 88 17:25:41 GMT Reply-To: madd@bu-it.bu.edu Organization: Boston University Distributed Systems Group Lines: 70 I've been making real heavy use of Turbo Pascal 4.0 recently and I've come across some oddities that other users might like to be aware of. The ones I have found had to do with what happens when you close unopened files and a problem with the new exec function. As anyone who uses 3.0 and 4.0 knows, there are quite a few differences in the way files are handled now. Some of these differences introduced subtle incompatibilities. Try the following program under each and see the difference: { oddity.pas: this program shows an oddity in the way TP 4.0 works } program oddity; var f : text; {$i-} begin writeln('Before close function'); close(f); writeln('This will not print under TP 4.0'); if ioresult <> 0 then ; writeln('Done.') end. What will happen: Under 3.0, the (obviously invalid) close will not affect anything. Under 4.0, nothing will print (although no runtime error will be given) until ioresult is checked. This difference had me running in circles for awhile, since I used to code this like this: reset(f); if ioresult <> 0 then begin close(f); { just to be sure } writeln('Error opening file'); { tell user } halt { back to the world of mashdos } end; Another problem I ran into had to do with the new exec function in the dos unit. The exec function *can* cause memory allocation problems if you goof with the environment. I was working with a shell program so I'd changed the vector at memw[prefixseg:$002C] (PSP environment segment pointer) to point to my new environment. An exec function would work properly, but would leave the DOS memory allocation information in a munged state; further exec's would crash the system. This isn't really a bug in 4.0 (the Tech Ref guide says that touching that vector is a no-no) but it's something I ran across. My solution was to use the exec function to call 'command /c' to run my program. This is additional overhead that I didn't want, but it worked. Note: does anyone know any way of determining the size of the environment area given to a process? I need this and the Tech Ref Guide doesn't exactly tell you much about it. In fact, it doesn't tell you anything. Any help is greatly appreciated. For those of you who don't have 4.0 yet, get it. It makes programming in Pascal worthwhile (ok, possible). It's too bad that you can't alter the initialization code for a program; if you could, 4.0 would be almost powerful enough to write an operating system in; you almost never need machine code now. I'm tempted to try to write an OS in it anyway, but I suspect that it's a bit too closely tied to the MS-DOS environment for that. Happy hacking, jim frost madd@bu-it.bu.edu