[futurebasic] Re: [FB] Header translation

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2005 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Tue, 9 Aug 2005 08:19:42 +1200
Bernie wrote:

> Let's take fn GetControlProperty() as an example.
> Here's how it appears in Apple's header:
> extern OSStatus
> GetControlProperty(
>   ControlRef   control,
>   OSType       propertyCreator,
>   OSType       propertyTag,
>   UInt32       bufferSize,
>   UInt32 *     actualSize,
>   void *       propertyBuffer)
> and this is how it has been translated in FB:
> toolbox fn GetControlProperty(
>   ControlRef c,
>   OSType propertyCreator,
>   OSType propertyTag,
>   UInt32 bufferSize,
>   UInt32 *actualSize,
>   ptr *propertyBuffer ) = OSStatus
>
> 1) What is the * (star) for in "UInt32 * actualSize"? Do we need it  
> in the FB translation?
> 2) Is it fair to say that whenever the param type appears as  
> "void", we can substitute "ptr" ?
>

* means that the parameter is a pointer. In C, pointers are in  
general typed, according to what they point to. Hence for example
  UInt32 * actualSize (or UInt32* actualSize, or UInt32 *actualSize)
Here, actualSize is an address into which GetControlProperty will  
write a 4-byte value.

Sometimes the type is unknown at compile time, i.e. the address is  
that of arbitrary or unknown data. void* is the delightful way by  
which C expresses a type-agnostic pointer.

Most pointers in FB are untyped. The exact equivalent of void* in FB  
is ptr (or pointer). A correct translation is therefore:
toolbox fn GetControlProperty(
   ControlRef c,
   OSType propertyCreator,
   OSType propertyTag,
   UInt32 bufferSize,
   UInt32 *actualSize,
   ptr    propertyBuffer ) = OSStatus

Few toolbox conversions in FB do this correctly. Most translators  
evidently found themselves unable or unwilling to remove *.  If the *  
is present, it doesn't matter much what is placed in front of it.  
These are all the same to FB:
  ptr* propertyBuffer
  long* propertyBuffer
  byte* propertyBuffer

Robert P.