Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!udel!rochester!pt.cs.cmu.edu!andrew.cmu.edu!jv0l+ From: jv0l+@andrew.cmu.edu (Justin Chris Vallon) Newsgroups: comp.sys.mac.programmer Subject: Re: TWO Byte Characters, SysEnvirons -- Help Message-ID: Date: 15 Apr 88 04:52:57 GMT Organization: Carnegie Mellon University Lines: 54 In-Reply-To: <742@unioncs.UUCP> I believe that you are confused about the size of a character. sizeof(char) is 1 in Pascal, in text files, and when using the Mac Toolbox If you are computing the sizeof a char by looking at the space occupied in a record or on the stack frame, then you need some background on the 680x0 family: The 68000 uP has a 16 bit data bus, the lower half covering all of the even bytes in memory, the upper half dealing with the odd bytes. When the 68000 reads integers (2-bytes) and long-integers (4-bytes) from memory, they must be word aligned, so that the entire data can be read in 1 fetch. This means that the ad dress of an int/long must always be EVEN. If an attempt is made to read an int/long from an ODD memory address, you get the (probably familiar) System Error ID=02 Now, for the 2-byte char size. Let's say that you have declared a pascal record with an int, a char, a long and a boolean: DataType = Record anInt: integer; aChar: char; aLong: longInt; aBool: boolean; End; Computing offsets into the record just using data sizes (this is not correct, you'll see why later): offset for anInt = 0; sizeof(integer) = 2 aChar = 2; sizeof(char) = 1 aLong = 3; sizeof(long) = 4 aChar = 7; sizeof(char) = 1 length of record = 8 bytes However, notice that aLong (a longInt) is not on a word boundary. To fix this, the compiler word-aligns any variable longer than 1 byte. So, the modified offsets are: offset for anInt = 0; sizeof(integer) = 2 aChar = 2; sizeof(char) = 1 aLong = 3->4; sizeof(longInt) = 4 aBool = 8; sizeof(boolean) = 1 length of record = 9 bytes Now, if you were to compute the size allocated to aChar, it would be offset(aLong) - offset(aChar) = 4-2 = 2! However, only 1 byte is used :-( The same argument holds true for pushing variables onto the stack. Since an interrupt may occur at any time, and addresses (longs) are stored on the stack, the stack pointer must always be EVEN. So, pushing a 1-byte character onto the stack effectively uses 2-bytes of stack space to make the SP word-aligned. Hope this answers your question. If it doesn't, then I'm lost, too :-) -Justin