Ben Combee a écrit :

> At 09:18 AM 11/9/2003, Luc Le Blanc wrote:
> >I have a form gadget for which the only persistent data I need to keep
> >holds in 2 UInt16s, so instead of keeping the gadget data somewhere else
> >and pass a data pointer to the gadget, I want to store the gadget data
> >right in the Gadget void *data field. So I defined:
> >
> >typedef struct
> >{
> >     UInt16      color;
> >     UInt16      resID;
> >} GadgetData;            // same size as a void *
> >
> >and initialize my gadget like this:
> >
> >GadgetData          data;
> >
> >data.color = traceColor;
> >data.resID = TraceColorString;
> >
> >FrmSetGadgetData( form, FrmGetObjectIndex( form, PrefsTraceColorGadget
> >), ( void * ) data );
> >
> >But the CW 8.3 compiler refuses this explicit cast to void *. What's
> >wrong?
>
> Only pointer or integral types can be cast to void *.  Try something like:
>
>      (void *)((UInt32)color << 16 | (UInt32)resID)
>
> The compiler won't treat a 32-bit long struct like an integral type.  You
> could also write:
>
>      (void *)*(UInt32 *)&data
>
> which would read the whole structure contents as a single UInt32 from
> memory.  That code is safe on the 68K, but not safe in ARM code, as data
> could be two-byte aligned.
>
> --
> Ben Combee <[EMAIL PROTECTED]>
> CodeWarrior for Palm OS technical lead
> Palm OS programming help @ www.palmoswerks.com

Can I do the same to read the gadget data with FrmGetGadgetData or do I
absolutely have to use a union? I tried
data = *( GadgetData *) FrmGetGadgetData( ...) but I get a bus error :(


--
Luc Le Blanc


--
Luc Le Blanc



--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to