3 ms·
re: controller id into a pointer If I understood correctly, the pointer is just a field in a common struct (common in event-handling code). As he mentions, it'
by AceJohnny2 12y ago
re: controller id into a pointer
If I understood correctly, the pointer is just a field in a common struct (common in event-handling code). As he mentions, it's usually used to point to extra data that you allocated separately in case you need it for that specific type of event, but what if you're having trouble with allocation and your data conveniently fits in the pointer field itself? So he just cast his controller id into the unused pointer parameter. He's not mangling any allocator data.
Which, if you're not going to use that pointer parameter otherwise, I think is perfectly sensible (and as long as you don't have code along the line of if (ptr != NULL) free(ptr);). I do it all the time... cough. For example, when creating a thread, you can pass it a void* to some data for it. I just cast a threadID integer into there. Hell, you'll see just that in the first example on a google search for "pthread example"!
- AmirS2 12y agoApparently there was top level code (that couldn't be changed as it was needed several other places) that DID free the pointer though... hopefully the controller id was just the lowest bit or two, which would then align back to zero or something when it came time to free ;-)
- jheriko 12y agoyeah, so he said the problem was that this pointer was freed out of his control. any way of packing data into that pointer suffers the same problem - except even worse, you are now freeing something that wasn't allocated.