On 09/17/2014 11:55 AM, Iñaki Baz Castillo wrote: > 2014-09-17 11:37 GMT+02:00 Saúl Ibarra Corretgé <[email protected]>: >> Then malloc one of these and pass &ctx->req to uv_udp_send. In the >> callback, you can do the following to get a pointer to your context: >> >> udp_send_ctx_t* ctx = container_of(req, udp_send_ctx_t, req); > > > Don't do that please. The "container_of" is just defined in Linux. > IMHO it is much more elegant to use the void* data field of the > uv_udp_send_t. >
Please elaborate, you didn't offer any proper reasoning as of why it's not a good idea. "I don't like/understand it" is not a valid reason. container_of is just a silly define that can be copied around if need be. We use it all across libuv: https://github.com/joyent/libuv/blob/master/src/uv-common.h#L45 > What I do in my C++ code (and in fact Saghul suggested it) is: > I don't remember when that was, but I've been using container_of for quite a while now, and one you get it there is no looking back. The code looks a lot more elegant and you avoid using that data pointer altogether. -- Saúl Ibarra Corretgé bettercallsaghul.com
signature.asc
Description: OpenPGP digital signature
