[futurebasic] Re: [FB] 'as pointer to' bug?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2002 : Group Archive : Group : All Groups

From: Alain Pastor <pixmix@...>
Date: Sun, 29 Sep 2002 14:59:17 +0200

Steven J. Stratford wrote:
> This works in OS 9, but application quits unexpectedly in OS X before
> printing anything. Using R7. Any ideas? If I "dim test as b" it works fine
> but I need the pointer.
> 
> begin record a
> dim something as long
> end record
> 
> begin record b
> dim whatever as a
> end record
> 
> dim test as ^b
> 
> window 1
> test.whatever.something = 1
> 
> print test.whatever.something
> 
> do
> handleevents
> until 0
> 

I think the problem in your code is that the following statement:

dim test as ^b

declares the variable test as a pointer to some kind of variable, but 
that it doesn't allocate the storage for the variable pointed to by 
the pointer.

The value you are setting for the field of the undeclared variable is 
placed somewhere in memory and this may crash the program immediately 
or not depending on the severity of the mess produced. Perhaps the 
immediate crash in OS X is due to the protected memory scheme.

I think, your code should read like this:

dim myVariable as b // this allocates the actual storage
dim test as ^b // declares a pointer to a variable of type b

test = @myVariable // sets the pointer so that it points to the variable

In fact, in the snippet of code above, it is useless to declare a 
pointer, since you just need to declare a variable of type b.
-- 
Cheers,

A. Pastor