Skip to content

Commit c0f1bd1

Browse files
Make some operators in IPAddress const
These functions do not modify the IPAddress object, but were not marked as const. This meant that you could not do: void set_ip(const IPAddress& ip) { uint32_t copy = ip; } Since calling operator uint32_t() on ip would discard the constness of the reference.
1 parent 5746ffa commit c0f1bd1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cores/arduino/IPAddress.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ IPAddress& IPAddress::operator=(uint32_t address)
3737
return *this;
3838
}
3939

40-
bool IPAddress::operator==(const uint8_t* addr)
40+
bool IPAddress::operator==(const uint8_t* addr) const
4141
{
4242
return memcmp(addr, _address, sizeof(_address)) == 0;
4343
}

cores/arduino/IPAddress.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class IPAddress : public Printable {
4848

4949
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
5050
// to a four-byte uint8_t array is expected
51-
operator uint32_t() { return *((uint32_t*)_address); };
52-
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
53-
bool operator==(const uint8_t* addr);
51+
operator uint32_t() const { return *((uint32_t*)_address); };
52+
bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
53+
bool operator==(const uint8_t* addr) const;
5454

5555
// Overloaded index operator to allow getting and setting individual octets of the address
5656
uint8_t operator[](int index) const { return _address[index]; };

0 commit comments

Comments
 (0)