gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Newbie : What is -> ?

#10419 - goro - Thu Sep 04, 2003 2:21 pm

I know that this is the arrow operator but can someone tell me what it does in the gba programming world in 'kids language' because I'm finding it hard to grasp it's concept.

I read somewhere that it "references individual aggregate data-type elements under a single name"

I know that agregate data-types probably means structures but I still find it hard to understand :-

Code:
bg->tileData = (u16*)CharBaseBlock(bg->charBaseBlock);
   bg->mapData = (u16*)ScreenBaseBlock(bg->screenBaseBlock);
   temp = bg->size | (bg->charBaseBlock<<CHAR_SHIFT) | (bg->screenBaseBlock<<SCREEN_SHIFT)
      | bg->colorMode | bg->mosaic | bg->wraparound;

#10420 - Lupin - Thu Sep 04, 2003 2:36 pm

That's easy... ok, lets say you have an very very big structure (not an Array!) containing bitmap data for example, then you may not want to pass the whole data to an function, you'll just pass the adress (where the data is located) to the function, then your function header will look something like this:

void MyFunc(MyBIGStructure *image) {
//Dereference an value in the structure
vartest=image->width;
}

The -> looks for the actual data located at the adress of "image", the operator is pretty much the array operator [x] (yes, they basically do the same)

#10425 - Master S - Thu Sep 04, 2003 3:02 pm

an example :

// Test structure
typedef struct
{
int Member;
} TTest;

// Instance of oure structure
TTest Test;
// Pointer to a instance of oure structure
TTest *pTest;

// Make pTest point to Test
pTest = &Test;

The folowing 3 examples will do the same :

Test.Member = 3;

(*pTest).Member = 3;

pTest->Meber = 3;

Saves some typing ;)

#10431 - goro - Thu Sep 04, 2003 5:14 pm

Wow, Thanks you guys.

I think I understand but my brain is fried (due to trying to understand many other things today) but I'll read it again 20 times and do some revision on structs, arrays and pointers.

Thanks again for all of your help.