[futurebasic] Re: [FB] Porting program

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Fri, 18 Jan 2008 22:08:20 +1300
maxclass@... wrote:

> On Jan 17, 2008, at 8:01 PM, Bob Bryce wrote:
> PROBLEM: My original program had many, many Record structures like;
>
>> BEGIN RECORD MTInfo
>>  DIM as str255 MTfontName$
>>  DIM 4 MTfontSize$
>>  DIM as str255 MTStyleName$
>>  DIM 4 MTStyleNumber$
>>  DIM 4 MTsb$
>>  DIM 4 MTsa$
>>  DIM 4 MTsl$
>>  DIM 4 MTBold%
>>  DIM 4 MTItalic%
>>  DIM 4 MTUnderline%
>>  DIM MTButtonState%
>> END RECORD
>>
>> DIM gMT.MTInfo
>
> Maybe start by cleaning up the records something like the following.  
> This should make the code FBtoC compatible and compile with out any  
> errors.
>
> BEGIN RECORD MTInfo
>  DIM as str255 MTfontName
>  DIM as str255 MTStyleName
>  DIM as str15 MTfontSize
>  DIM as str15 MTStyleNumber
>  DIM as str15 MTsb
>  DIM as str15 MTsa
>  DIM as str15 MTsl
>  DIM as short MTBold
>  DIM as short MTItalic
>  DIM as short MTUnderline
>  DIM as short MTButtonState
> END RECORD
>
> DIM as MTInfo gMT


Indeed that is cleaner and uses correct syntax for all fields.

One clarification: there is no need to change the custom-sized string  
fields to Str15.
Declarations like
   dim 4 myLittleStringVar$
give rise to a string variable (or string field) that is 6 bytes long,  
whereas Str15 occupies 16 bytes.
Early previews of FBtoC choked on custom-sized strings, but released  
versions handle them correctly.

Robert P.

For C aficionados, this extract from build_goodies/FBtoC.h shows how  
custom-sized string vars are implemented by FBtoC:

// custom-sized strings [those already in MacTypes.h are commented out]
typedef unsigned char Str1[2];
typedef unsigned char Str3[4];
typedef unsigned char Str5[6];
typedef unsigned char Str7[8];
typedef unsigned char Str9[10];
typedef unsigned char Str11[12];
typedef unsigned char Str13[14];
//typedef unsigned char Str15[16];
typedef unsigned char Str17[18];
...