|
From: | Simon Goldschmidt |
Subject: | Re: [lwip-devel] Concern over strict aliasing and undefined behavior? |
Date: | Wed, 9 Oct 2013 21:50:54 +0200 |
Mike Pontillo wrote:
And if you add to that the fact that most embedded compilers are way behind the standard, it's even less probable that people actually thought about this back then.
I thought this wasn't a violation because of using a void pointer. But then again, I never really looked into the issue: it seems like all (embedded) compilers I used lwIP with so far did not have a problem with how lwIP casts pointers.
I think you have to differ between multiple cases here: the one fixed in that archived message was taking one struct and letting another type point to it. This has been fixed. However with the input/output functions, it's a different thing: data will not be written to memory and read back (aside from using the loop back connection maybe), but instead it's written there and sent out or received by the driver and read by the stack/application. In this case, what other options are left when implementing a stack with decent performance (I.e. not copying the data)? I can't think of one. Also, since the data is not reused but sent out, I think the chances of optimization breaking the code here is pretty low. If you take strict aliasing as "not allowing different pointer types to the same data", you're good with the lwIP input/output functions, as (aside from the ethernet driver sending/receiving the buffer), the data is not otherwise referenced. To sum it up, if you find more bugs like the one above, please let us know (I'm not sure there are none). Also, if you have an idea how to better implement it, you're welcome to share it! But as of yet, I don't know of any reported problem with this code, even if it might technically not cleanly follow the standard. Simon |
[Prev in Thread] | Current Thread | [Next in Thread] |