On 09/17/2014 12:18 PM, Iñaki Baz Castillo wrote: > 2014-09-17 12:00 GMT+02:00 Saúl Ibarra Corretgé <[email protected]>: >>> 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. > > > You are basically doing (in uv_udp_send_cb): > > udp_send_ctx_t* ctx = container_of(req, udp_send_ctx_t, req); > > which becomes: > > udp_send_ctx_t* ctx = ((udp_send_ctx*) ((char*) (req) - > offsetof(udp_send_ctx, req))); > > > I do: > > - when sending: > &ctx->req.data = (void*)ctx; > > - in uv_udp_send_cb: > udp_send_ctx_t* ctx = (udp_send_ctx_t*)req->data; > > > You require a ugly macro which relies on the offsetof() macro defined > for ANSI C, which may result in big issues when using with C++ > objects: >
There is an alternative ContainerOf thing in Node, for the curious. libuv is a C library, so whatever I say works for C and a C compiler. This might be the reason why I suggested you did it that way in the past. Anyway, it may come down to a matter of taste, but dismissing my reply because "it's ugly" and "only works on Linux" is deceiving, and incorrect. -- Saúl Ibarra Corretgé bettercallsaghul.com
signature.asc
Description: OpenPGP digital signature
