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: ----------------------- -Wno-invalid-offsetof (C++ and Objective-C++ only) Suppress warnings from applying the ‘offsetof’ macro to a non-POD type. According to the 1998 ISO C++ standard, applying ‘offsetof’ to a non-POD type is undefined. In existing C++ implementations, however, ‘offsetof’ typically gives meaningful results even when applied to certain kinds of non-POD types. (Such as a simple ‘struct’ that fails to be a POD type only by virtue of having a constructor.) This flag is for users who are aware that they are writing nonportable code and who have deliberately chosen to ignore the warning about it. The restrictions on ‘offsetof’ may be relaxed in a future version of the C++ standard. ----------------------- Anyhow, may I know why your code is better than mine? - Your code saves a void* assignement (wow!!!!). - Mine does not use macros and uses UV public API. -- Iñaki Baz Castillo <[email protected]> -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
