1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-30 11:24:12 +01:00
Arduino/hardware/arduino/avr
Matthijs Kooijman 3035239a4e Use a union in IPAddress for uint8_t[] <-> uint32_t conversion
Previously, pointer casting was used, but this resulted in strict-aliasing warnings:

IPAddress.h: In member function ‘IPAddress::operator uint32_t() const’:
IPAddress.h:46:61: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     operator uint32_t() const { return *((uint32_t*)_address); };
                                                             ^
IPAddress.h: In member function ‘bool IPAddress::operator==(const IPAddress&) const’:
IPAddress.h:47:81: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
                                                                                 ^
IPAddress.h:47:114: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };

Converting between unrelated types like this is commonly done using a union,
which do not break the strict-aliasing rules. Using that union, inside
IPAddress there is now an attribute _address.bytes for the raw byte
arra, or _address.dword for the uint32_t version.

Since we now have easy access to the uint32_t version, this also removes
two memcpy invocations that can just become assignments.

This patch does not change the generated code in any way, the compiler
already optimized away the memcpy calls and the previous casts mean
exactly the same.

This is a different implementation of a part of #1399 and it helps
toward fixing #1728.
2014-02-19 16:09:29 +01:00
..
bootloaders merge 2013-10-14 12:42:42 +02:00
cores/arduino Use a union in IPAddress for uint8_t[] <-> uint32_t conversion 2014-02-19 16:09:29 +01:00
firmwares Merged 1.0.5 2013-04-03 13:51:04 +02:00
libraries Revert "SPI library to new format" 2013-11-21 15:05:36 +01:00
variants Merge branch 'master' into ide-1.5.x 2014-02-12 17:17:33 +01:00
boards.txt In boards.txt, rename atmega328diecimila to diecimila 2013-12-08 18:16:31 +01:00
platform.txt Compile with -x assembler-with-cpp instead of -assembler-with-cpp. 2014-01-21 21:57:35 +01:00
programmers.txt Set correct speed of Arduino ISP programmer 2013-04-06 01:59:25 +02:00