[fpc-pascal] Carbon: i386 and PPC API differences

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Sep 29 16:26:12 CEST 2008

On 29 Sep 2008, at 16:04, EarMaster - Bent Olsen wrote:

> I use Xcode to find samples of codes and try to make it work on FPC/ 
> Lazarus.
> One example opens an AUGraph and send MIDI messages - a small  
> sample. It
> calls AUGraphNewNode which returns a node from 1 to n, and it works
> perfectly in FPC on Carbon/i386, and of course for Xcode on the same
> machine.
> The same code works fine in Xcode on Carbon/PowerPC, but does not  
> return any
> nodes in FPC on Carbon/PowerPC.
> // -------- Code snips
> // Pascal
> type
>  ComponentDescription = record
>    componentType: OSType;
>    componentSubType: OSType;
>    componentManufacturer: OSType;
>    componentFlags: UInt32;
>    componentFlagMask: UInt32;
>  end;
> function AUGraphNewNode(inGraph: AUGraph; const inDescription:
> ComponentDescription;
>  inClassDataSize: LongWord; inClassData : Pointer; var outNode :  
> AUNode):
> OSStatus;
>  external name '_AUGraphNewNode'; mwpascal; //

"const inDescription: ComponentDescription" is wrong, because FPC does  
not guarantee that this will be passed by reference (especially in  
case of C imports, because in C "const" also means "pass by value").  
Either use a pointer type, or use "var" instead. There is no constvar  
or similar specifier.

Also add {$packrecords C} to your source to ensure that the records  
are properly packed, and translate "unsigned long" using the "culong"  
type from the ctypes unit rather than using uint32 ("unsigned long" is  
not the same as uint32 on all platforms, e.g. it's different on 64 bit  
Mac OS X).


More information about the fpc-pascal mailing list