Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!agate!garnet.berkeley.edu!physi-hf From: physi-hf@garnet.berkeley.edu (Howard Haruo Fukuda) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C Problem Message-ID: <1990Nov20.070429.26286@agate.berkeley.edu> Date: 20 Nov 90 07:04:29 GMT References: <4742@husc6.harvard.edu> <1990Nov18.070105.20735@agate.berkeley.edu> Sender: usenet@agate.berkeley.edu (USENET Administrator) Distribution: usa Organization: University of California, Berkeley Lines: 26 In article phils@chaos.cs.brandeis.edu (Phil Shapiro) writes: >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 problem was that when I declared the string in a function: Str255="\pThis is a string"; the pascal string was at an odd address (among the global variables). When the function was entered, space was allocated on the stack for the string, and then Think C tried to copy to data from where the string was in global to the space allocated on the stack with a MOVE.L/DBF loop. This caused a bus error. There were no funny casts involved or anything. The string declaration is the only thing that gets executed before the bus error halts execution. My point is that this is a perfectly valid statement in C and that the error is caused (in MHO) by the compiler. -Howard