[ENet-discuss] Using packet-data w/o a memcpy()?

Mike Diehl mdiehl at diehlnet.com
Thu May 13 13:05:18 PDT 2010


On Wednesday 12 May 2010 2:30:04 am RAULO Emmanuel IT&L at bs wrote:
> > My reading of the docs indicate that event.packet-data is a enet_uint8 *,
> > which is typecast from a pointer to char.  This implies that I should be
> > able to cast it to void*
>
> Yup, any pointer type can be cast to void*.
>
> > void	*buffer;
> >
> > buffer = (void) event.packet->data;
> >
> > But this didn't seem to work.  Like I said, I'm a bit rusty...  So I was
> > on the right track?  I just have to fiddle with syntax, then.
>
> That should be buffer = (void*)event.packet->data; as you want a pointer.
> You don't even have to cast explicitely as void* is a "more general"
> type than uint8* so buffer=event.packet->data; will work as well.
> Explicit cast is only needed with pointers when the destination type is
> "more specific" than the original type, e.g. struct SomeStruct
> *structPtr = (struct SomeStruct*)buffer;

So, I need to get a refresher on C pointers.  I KNEW this was done all the 
time, I just couldn't get it to work.  Thanks for the quick tutorial, btw.

-- 

Take care and have fun,
Mike Diehl.


More information about the ENet-discuss mailing list