[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-devel] Concern over strict aliasing and undefined behavior?
From: |
Valery Ushakov |
Subject: |
Re: [lwip-devel] Concern over strict aliasing and undefined behavior? |
Date: |
Wed, 9 Oct 2013 02:10:22 +0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Oct 07, 2013 at 10:40:18 -0500, Sam Caldwell wrote:
> I am currently doing some network programming and ran into the
> problem of strict-aliasing when I wanted to cast a portion of an
> incoming buffer to a struct modeling a network header.
> Unfortunately, this violates strict-aliasing, and therefore has
> undefined behavior. I'm looking for the most efficient way to do
> this that is correct, portable, and well-defined.
[...]
> Additionally, here is a more thorough write-up of my understanding
> of the issue as a stack-overflow question:
>
> http://stackoverflow.com/questions/19165134/correct-portable-way-to-interpret-buffer-as-a-struct
You might find Derek Jones exegesis of the C standard helpful
http://www.knosof.co.uk/cbook/cbook.html
Your original "uint8_t *" version at stackoverflow is probably ok too,
since uint8_t is pretty much guaranteed to be defined as "a character
type", the last item in the aliasing rules list in 6.5 [#7].
-uwe