What's this mean in C: "->" ?

Community Forums/General Help/What's this mean in C: "->" ?

sswift(Posted 2009) [#1]
I'd google it but google doesn't work with symbols like that.


big10p(Posted 2009) [#2]
It's the operator to dereference a pointer. i.e. access the member data the pointer is, erm, pointing to.


Jim Teeuwen(Posted 2009) [#3]
I suggest you start here:

"A C++ Tutorial for Complete Beginners # 1" -> http://www.1cplusplusstreet.com/vb/scripts/ShowCode.asp?txtCodeId=2040&lngWId=3


Dabhand(Posted 2009) [#4]
Member access operator.

http://msdn.microsoft.com/en-us/library/b930c881(VS.80).aspx

One of them anyway, the other is a period [.]

Dabz


sswift(Posted 2009) [#5]
Jim T:
I'm not trying to learn C, I'm trying to access one stupid event that BlitzMax doesn't reveal which will give me the raw movement data from the mouse. :-)


sswift(Posted 2009) [#6]
Hm...

RAWINPUT* raw = (RAWINPUT*)lpb;

So if I'm reading this right... lpb is an int which contains a pointer. This is converted to a RAWINPUT pointer, and stored in a variable raw, which is of type RAWINPUT pointer.

At least that's how it first appears...

But this is the code that's in:

	Case WM_INPUT

	    		dwSize:Int = 40
			lpb:Byte[40]
    
			GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, SizeOf(RAWINPUTHEADER));
    
			RAWINPUT* raw = (RAWINPUT*)lpb; ' raw is a pointer to data of type RAWINPUT.  But why
    
			If (raw->header.dwType == RIM_TYPEMOUSE) 
				Int xPosRelative = raw->data.mouse.lLastX;
				Int yPosRelative = raw->data.mouse.lLastY;
			EndIf



Hacked up a bit by me while converting it to blitzmax... But anyway, lpb is an array of 40 bytes. So (RAWINPUT*)lpb can't be converting an int to a pointer... Is it converting a pointer to a pointer of a different type maybe? I guess if it's an array being returned from the function it would have to be a pointer.

Maybe what this is doing is taking the returned pointer lpb which is a pointer to an array of an undefined type, and then converting that pointer to a pointer to the struct RAWINPUT, and the array is 40 bytes because the struct is 40 bytes? Hm. Why wouldn't they have used sizeof() when declaring the array though to make sure it's always the right size if the strucutre changes?

Ugh. What a pain in the ass this seemingly simple task has turned out to be.


big10p(Posted 2009) [#7]
In C, the name of an array is considered a pointer to the first element of that array. The cast is converting that pointer to a different type and assigning it to raw.


nawi(Posted 2009) [#8]
(*pointer_to_struct).struct_variable
is the same as
pointer_to_struct->struct_variable
Well, atleast in C++, C should be same I guess..