ArduinoCore-avr/cores/arduino
Matthijs Kooijman f76c327aae 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
..
avr-libc Increased malloc margin to 128. 2013-03-29 11:48:35 +01:00
Arduino.h Added license for Arduino.h, binary.h and main.cpp 2014-02-10 12:55:16 +01:00
CDC.cpp Merge branch 'master' into ide-1.5.x 2013-09-30 16:25:10 +02:00
Client.h Added license for Client, IPAddressm and Server 2014-02-10 12:55:16 +01:00
HID.cpp fixed logic error in Keyboard.release() - now removes every occurrence of a key if it's present more than once 2012-03-28 19:46:32 -04:00
HardwareSerial.cpp In HardwareSerial, don't use int for buffer indices 2014-02-14 10:25:34 +01:00
HardwareSerial.h Added license for avr/HardwareSerial. 2014-02-10 12:55:16 +01:00
HardwareSerial0.cpp Added license for avr/HardwareSerial. 2014-02-10 12:55:16 +01:00
HardwareSerial1.cpp Added license for avr/HardwareSerial. 2014-02-10 12:55:16 +01:00
HardwareSerial2.cpp Added license for avr/HardwareSerial. 2014-02-10 12:55:16 +01:00
HardwareSerial3.cpp Added license for avr/HardwareSerial. 2014-02-10 12:55:16 +01:00
HardwareSerial_private.h Added license for avr/HardwareSerial. 2014-02-10 12:55:16 +01:00
IPAddress.cpp Use a union in IPAddress for uint8_t[] <-> uint32_t conversion 2014-02-19 16:09:29 +01:00
IPAddress.h Use a union in IPAddress for uint8_t[] <-> uint32_t conversion 2014-02-19 16:09:29 +01:00
Platform.h support for non-Leonardo boards is back! 2011-08-30 11:50:08 -04:00
Print.cpp Merge branch 'cast' of github.com:Lauszus/Arduino into Lauszus-cast 2013-12-31 20:11:08 +01:00
Print.h Add Print::write(const char *, size_t) 2013-12-24 13:22:42 +01:00
Printable.h Merge branch 'new-extension' of https://github.com/arduino/Arduino 2011-08-27 23:53:42 +01:00
Server.h Added license for Client, IPAddressm and Server 2014-02-10 12:55:16 +01:00
Stream.cpp Adding readString() and readStringUntil() to Stream (Adrian McEwen). 2012-05-16 15:39:34 -04:00
Stream.h Add uint8_t* versions of methods in Stream 2013-12-24 13:22:42 +01:00
Tone.cpp fixed permissions on a lot of text files. see #1116 2012-12-10 10:42:49 +01:00
USBAPI.h Centrally decide which hardware UARTS are available 2014-01-22 09:38:34 +01:00
USBCore.cpp Remove hardcoded product names (all provided for in boards.txt) 2013-07-17 14:38:05 +02:00
USBCore.h Serial via USB works 2011-08-14 16:59:34 -04:00
USBDesc.h sketch USB VID and PID values are passed in from boards.txt at compile time now. changed sketch PIDs to final values. also uncommented Micro section in boards.txt 2012-04-09 08:06:35 -04:00
Udp.h Making Print::write(char *) non-virtual. 2011-09-07 18:41:05 -04:00
WCharacter.h Replacing custom String.toInt() function with a call to atol(). 2010-12-03 23:12:41 -05:00
WInterrupts.c Added support to INT6 on Leonardo. 2013-05-13 21:22:59 +02:00
WMath.cpp Improving third-party hardware support: 2009-11-21 23:23:43 +00:00
WString.cpp Improved portability of String class (maniacbug) 2014-01-01 17:22:40 +01:00
WString.h Fixed String class regression after f80c6c5f35cddcf4761a3c97feb8504425e9d27d 2013-09-03 18:40:30 +02:00
binary.h Added license for Arduino.h, binary.h and main.cpp 2014-02-10 12:55:16 +01:00
hooks.c Added general yield()-hook for cooperative scheduling development (part 2) 2012-11-02 18:12:21 +01:00
main.cpp Added license for Arduino.h, binary.h and main.cpp 2014-02-10 12:55:16 +01:00
new.cpp Add trivial new[] and delete[] operators (Justin R. Cutler) 2012-12-16 14:30:12 +01:00
new.h Add trivial new[] and delete[] operators (Justin R. Cutler) 2012-12-16 14:30:12 +01:00
wiring.c Merged 1.0.5 2013-04-03 13:51:04 +02:00
wiring_analog.c Merge branch 'issue1366' of github.com:Lauszus/Arduino into Lauszus-issue1366 2013-07-31 17:22:12 +02:00
wiring_digital.c Merge branch 'master' of github.com:arduino/Arduino into new-extension 2012-01-10 12:02:27 -05:00
wiring_private.h Merged 1.0.5 2013-05-29 18:30:36 +02:00
wiring_pulse.c fixed permissions on a lot of text files. see #1116 2012-12-10 10:42:49 +01:00
wiring_shift.c fixed permissions on a lot of text files. see #1116 2012-12-10 10:42:49 +01:00