[Gd-hackers] Melange structure packing/alignment

Jay Lieske lisper at jlieske.com
Sat Sep 23 20:11:18 CEST 2006


D2Cers--

I've been working on an expanded Carbon library for d2c, using Melange 
rather than a hand-coded interface.  My port of the simple-starter 
sample application was crashing in the event handlers because the 
WindowRef values were bad.  I looked into it in more detail, and found 
that Melange was generating this for the C EventRecord.message field:

define sealed inline method message
     (ptr :: <EventRecord>) => (result :: <UInt32>);
   unsigned-long-at(ptr, offset: 4);
end method message;

whereas the existing (hand-coded) API looks like this:

define method message-value ( event :: <EventRecord*> )
=> ( message :: <integer> )
	unsigned-long-at(event, offset: 2 );
end method message-value;

The Melange-generated code is not using the right structure 
packing/alignment algorithm.  Most of the Mac headers have this 
directive
#pragma options align=mac68k
which packs on 2-byte boundaries (for the most part).

Is there any way to get Melange to use the same structure alignment?  
This is with d2c 2.4.0 on Mac OS 1.3.9.

Thanks,
--jay




More information about the hackers mailing list