Why const? Since ptr increases later in the function, I donβt understand why it is declared const.
Because it is not a const pointer, but an object that it points to. What you are talking about will be written as float *const ptr , but as you can see, ptr not declared as such.
Why .ptr?
Because the union may not have the same size as the float . Imagine this array:
union * union * union * union * +0 +1 +2 +3 (correct) +----------------+----------------+----------------+ union boundaries: | union | union | union | +----------------+----------------+----------------+ float boundaries: | float |junk| float |junk| float |junk| +----------------+----------------+----------------+ ^ ^ ^ ^ ^ float * float * float * float * float * +0 +1 +2 +3 +4 ^--------- these are all wrong ----------^
If you get a pointer to the first float and apply the arithmetic of the pointer on it, this will lead to incorrect results if union greater than float .
user529758 06 Oct '13 at 8:01 2013-10-06 08:01
source share