On Fri, 22 Feb 2008, Kirk Wallace wrote:
> Another bit I don't understand:
>
>    /* STEP 3: allocate shared memory for joystick data */
>    js_data = (hal_js_t *) hal_malloc(sizeof(hal_js_t));
>    if (js_data == 0) {
>       printf( "ERROR: hal_malloc() failed\n");
>       hal_exit(comp_id);
>       return -1;
>    }
>
> hal_js_t is a defined variable type.
> sizeof(hal_js_t) is the memory size of this type.
> hal_malloc(sizeof(hal_js_t)) returns the memory location of this
> variable.
> I don't understand what (hal_js_t *) does. hal_js_t is a type so it is
> similar to (int *)?

hal_malloc returns a (void *) pointer; this would presumably make 
subsequent code complain about pointer mismatches, and the compiler 
wouldn't know where to look in the data structure for variables like 
&(js_data->axis[n]). the (hal_js_t *) casts the returned pointer to the 
correct pointer type.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to