[futurebasic] Re: [FB] Points on Pointers

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

From: Ken Shmidheiser <kshmidheiser@...>
Date: Wed, 22 Sep 2004 23:36:01 -0400
Jay wrote:

I wonder, from your statement, whether you're confusing pointers and
handles. The parking lot illustration deals with handles (a pointer to
a pointer). You can safely think of a pointer as a var holding the
address of the data you're reading. You read it by PEEKing, or using
the .Nil syntax. When you use .Nil, you must indicate what type of data
you want to read. In this case you use % for INT, because that's the
way your array is defined.

I've amended your example to work using pointers. If it's handles you
want help on, feel free to ask again.

Jay,

Thanks for the quick response. FYI here is the C sample I was 
attempting to translate in my study of pointers.


int my_array[] = {1,23,17,4,-5,100};
int *ptr;

int main(void)
{
     int i;
     ptr = &my_array[0];     /* point our pointer to the first
                                       element of the array */
     printf("\n\n");
     for (i = 0; i < 6; i++)
     {
       printf("my_array[%d] = %d   ",i,my_array[i]);   /*<-- A */
       printf("ptr + %d = %d\n",i, *(ptr + i));        /*<-- B */
     }
     return 0;


This is much easier for me to understand than the FB equivalent. (I 
have been working a lot in ASCI C to improve my understanding of FB.) 
If I seem confused between handles and pointers, it's because I am. 
Since I now program exclusively in OS X, a more thorough 
understanding of pointers has become more incumbent upon me.

In the example you fixed for me, would there be a significant speed 
difference between using the pointer verses the standard incrementing 
of the array elements? Also, does using sizeof(int) cost any more 
overhead than simply using +2?

Also, since .nil& is for longs, and .nil% is for integers, is .nil$ 
for strings and .nil# for doubles? Or am I missing something?

Also, thanks to Robert Covington for his suggestions. Peeking and 
poking has always seemed less elegant to me than solutions in other 
languages.

Any tips in helping me in this quest will be appreciated. Again, I'm 
having to use C tutorials because I can find nothing written in FB 
that really servers as a pointer tutorial.

Ken
--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...