Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!bbn.com!nic!chaos.cs.brandeis.edu!chaos!phils From: phils@chaos.cs.brandeis.edu (Phil Shapiro) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C Problem Message-ID: Date: 19 Nov 90 20:17:04 GMT References: <1990Oct27.074058.10748@agate.berkeley.edu> <4742@husc6.harvard.edu> <1990Nov18.070105.20735@agate.berkeley.edu> Sender: @chaos.cs.brandeis.edu Distribution: usa Organization: Symantec Corp. Lines: 50 In-Reply-To: physi-hf@garnet.berkeley.edu's message of 18 Nov 90 07:01:05 GMT In article <1990Nov18.070105.20735@agate.berkeley.edu> physi-hf@garnet.berkeley.edu (Howard Haruo Fukuda) writes: I'm not sure I understand your response. My problem was that Think C was not putting my strings on word boundaries. The line: Str255="\pHuh???"; places the pascal string at an odd-numbered address (well, not neccessarily all the time). For some reason changing the line to: static Str255="\pHuh???"; does put the string on a word boundary. (Thanks to Steve Martin for telling about the above hack.) Why does this work? First, using "static" is not a solution, since globals may be odd aligned in the same way that locals are. Try: main() { static char c; static Str255 s; } and look at &c and &s in the debugger. The fact is, Think C only word aligns your data if it is necessary. The reason that Str255's do not necessarily have to be word aligned is that all 680x0 machines allow odd address when accessing byte-sized data. That is, a "MOVE.B (Ax), xxx" will never fail. So, if your strings are used for accessing characters you're all set. If, however, you declare a Str255 and then cast it into an integer pointer, you're asking for trouble. The answer is (as Rich said) to make sure that your strings are word aligned if you need it. This can be accomplished by declaring an int or long just before the string, or by always using NewPtr() to allocate string storage. The last time this came up, somebody mentioned some Toolbox routines that expect word aligned strings (like SetIText?). Does anybody have a list? -phil -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation Internet: phils@chaos.cs.brandeis.edu