home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 20073 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.2 KB  |  55 lines

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