home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!spool.mu.edu!darwin.sura.net!mojo.eng.umd.edu!russotto
- From: russotto@eng.umd.edu (Matthew T. Russotto)
- Subject: Re: Think Pascal->C conversion -- advice?
- Message-ID: <1992Dec19.025507.22441@eng.umd.edu>
- Date: Sat, 19 Dec 92 02:55:07 GMT
- Organization: Project GLUE, University of Maryland, College Park
- References: <1992Dec18.021125.23146@afterlife.ncsc.mil>
- Lines: 44
-
- In article <1992Dec18.021125.23146@afterlife.ncsc.mil> mssmith@afterlife.ncsc.mil (M. Scott Smith) writes:
- >
- >Hi..
- >
- > I'm in the process of converting a large, complex program written with
- >Think Pascal to Think C. I'm pretty fluent in both Pascal and C, and
- >programming the Mac, but I was curious if anyone else has done this and
- >what types of problems they ran into, or what types of things I should be
- >careful about.
- >
- > I am not the primary author of this code, so I'm not very familiar with
- >it, which puts me at a disadvantage. It's also quite large.
- >
- > Some things I see that might be a problem are translating things such as
- >packed arrays of boolean (in Pascal, which I believe are 1-bit in size) yo
- >something equivalent in C. (I can't use integers to represent booleans,
- >because 2 (or 4) bytes is much too large for something that only takes a bit.
- >Think C has a Boolean data type -- but this isn't part of ANSI C, is it?
- >This code needs to be ANSI-C compliant.) That's probably not a major hurdle,
- >but it's little things like that which pop up and make me more cautious.
-
- Those, and WITH statements, are probably the stickiest things to
- convert. You can use unsigned char to represent boolean, but that's
- still 1 byte. Think C's boolean type is nothing but
-
- typedef enum {false, true} boolean;
-
- and that's one byte. One way to do it is to declare
-
- foo: Packed Array[x...y] of Boolean;
- as
-
- unsigned char p_foo[(y-x+8)>>3];
-
- and access foo with some defines like
-
- #define foo(z) (p_foo[((z)-x)>>3]&(1<<(((z)-x)&3)))
-
- Ugly, but effective, if I've typed it right.
- --
- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu
- Some news readers expect "Disclaimer:" here.
- Just say NO to police searches and seizures. Make them use force.
- (not responsible for bodily harm resulting from following above advice)
-