Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!apple.com!dowdy From: dowdy@apple.com (Tom Dowdy) Newsgroups: comp.sys.mac.programmer Subject: Re: Quick ThinkC String question... Message-ID: <6714@internal.Apple.COM> Date: 15 Feb 90 17:35:35 GMT Sender: usenet@Apple.COM Distribution: usa Organization: Apple Computer, Inc. Lines: 37 References:<77108@tut.cis.ohio-state.edu> <20011@bellcore.bellcore.com> <1990Feb14.210352.28118@oracle.com> [ several people give suggestions for copying strings via procedures ] Here are some macros for doing similar things: #define PSTRCPY(P1, P2) BlockMove(P2, P1, P2[0]+1) and also #define PSTRCAT(P1, P2) \ BlockMove(&P2[1], &P1[(P1[0]+1)], P2[0]); \ P1[0] += P2[0]; Some cautions about these, however. First off, neither of them do any kind of error checking. In the first case, this usually isn't a problem when you are tossing Str255s around. In the second case, things *can* get more hairy, but this is the case of having strong requirements on the caller rather than in the called routine. As long as one is aware of what is going on, this isn't a problem. The second macro probably isn't the most efficient way to code this, and no doubt some C person will tell me as much, but I almost never use PSTRCAT except in debugging code. However, there is one *serious* problem to watch out for. I hope this is the correct reason for this. In MPW C, the "\p" directive isn't evaulated until late in the code gen, so at the macro level, taking the first position in the array as a length results in the value '\' rather than in the length of the string. The result of this is that you can't do PSTRCPY(myString, "\pTesting"); This can be annoying, but since all my strings come out of resources (as they should in final code), I work around it when I have to. I don't know if this also happens in Think C, it may be part of the ANSI C spec. Tom Dowdy Internet: dowdy@apple.COM Apple Computer MS:81EQ UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy 20525 Mariani Ave AppleLink: DOWDY1 Cupertino, CA 95014 "The 'Ooh-Ah' Bird is so called because it lays square eggs."