home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18551 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.7 KB  |  59 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!pageworks.com!world!eff!sol.ctr.columbia.edu!usc!elroy.jpl.nasa.gov!ames!data.nas.nasa.gov!taligent!kip-16.taligent.com!user
  3. From: keith@taligent.com (Keith Rollin)
  4. Subject: Re: faulty ANSI in Think C 5.0?
  5. Message-ID: <keith-171192135605@kip-16.taligent.com>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: usenet@taligent.com (More Bytes Than You Can Read)
  8. Organization: Taligent
  9. References: <1992Nov16.211648.23619@math.ucla.edu> <1ebg9lINNi8e@terminator.rs.itd.umich.edu>
  10. Date: Tue, 17 Nov 1992 22:01:26 GMT
  11. Lines: 46
  12.  
  13. In article <1ebg9lINNi8e@terminator.rs.itd.umich.edu>,
  14. potts@oit.itd.umich.edu (Paul Potts) wrote:
  15. > In article <1992Nov16.211648.23619@math.ucla.edu> dchopp@vicente.math.ucla.edu (David Chopp) writes:
  16. > >I'm curious if others have run into similar problems as I regarding using
  17. > >some ANSI subroutines in Think C 5.0.2 with TCL.  In particular, I have
  18. > >trouble using strcpy, strcmp, sprintf, to name a few.  I have found them
  19. > >to be sporadic in working properly and I'm wondering if I'm doing something
  20. > >wrong.  For example, in one object, I'll have two methods each using strcpy
  21. > >in them (all in the same file).  In one context, it works perfectly, in the
  22. > >other it fails to copy.  The arguments being passed are all correct (I've
  23. > >checked them several times).  
  24. > I'd say it is most likely that there is a problem in your program. I've
  25. > used sprintf, strcpy, strcmp, etc. and had them work fine. 
  26. > Some things to consider: are you testing the arguments under the source-level
  27. > debugger, or at runtime under MacsBug? The source-level debugger and the
  28. > low-level debugger can show different things. Under the source debugger
  29. > sometimes memory is better initialized, pointers tend not to penalize you
  30. > for writing to stray addresses, etc. Whenever I've had problems using
  31. > the string routines, they were caused by some other part of my code which
  32. > was trashing memory at runtime.
  33.  
  34. Another thing that occurs to me is that there could be problems if the
  35. strings are data members of handle-based objects, and the ANSI routines are
  36. in an unloaded code segment. If that's so, then a call like:
  37.  
  38.     strcmp(fMyString, "Test string");
  39.  
  40. can fail. This is because calling strcmp() will cause the code segment
  41. containing it to be loaded. This loading could cause the object owning
  42. fMyString to move AFTER its address has been taken and placed on the stack.
  43.  
  44. If this is the problem, there are at least three solutions:
  45.  
  46. 1) lock the object containing fMyString.
  47. 2) make sure the ANSI library is in a resident segment
  48. 3) copy fMyString into a local variable (oops! this requires access to
  49. strcpy!
  50.    infinite page fault has occured -- shutting down...)
  51.  
  52. -----
  53. Keith Rollin
  54. Phantom Programmer
  55. Taligent, Inc.
  56.