ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Multiple instances of INADDR_NONE #1007

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Sketch with two files, each importing (directly or indirectly) IPAddress.h
2. avr-nm -n on the resulting elf (on Windows)

What is the expected output? What do you see instead?
Expect only a single instance of INADDR_NONE in .bss section, but multiple are 
allocated, consuming precious SRAM space (in my case of a bigger piece of 
software, seven instances).

Note also that IPAddress consumes six bytes, not four, due to the class pointer 
required for the virtual function.

This is on arduino-1.0.1 under Windows 7.

Please provide any additional information below.
Suggest to declare INADDR_NONE extern in IPAddress.h, and to define it in 
IPAddress.cpp.

Original issue reported on code.google.com by sebastia...@googlemail.com on 16 Aug 2012 at 6:20

GoogleCodeExporter commented 9 years ago
This also occours on arduino 1.0.1 under windows XP, I have a sketch 29Kbyt 
that uses both Ethernet.h and EthernetUdp.h that throws up INADDR_NONE 8 times. 
This uses up a lot of SRAM especially when your trying to improve the sketch so 
it does not crash because variables run into the stack!

Original comment by brucedur...@btinternet.com on 26 Feb 2013 at 8:24

GoogleCodeExporter commented 9 years ago
I believe that I've found another solution to this!! 

INADDR_NONE is only used by Dns.cpp so why is it declared as a const at the end 
if IPAddress.h as though its an afterthought?? 

My solution is to doctor both IPAddress.h (which is in 
x:\..\arduino-1.0.1\hardware\arduino\cores\arduino) to remark out the line 
'const IPAddress INADDR_NONE(0,0,0,0);' and to add this line to the Dns.cpp 
(which is in x:\..\arduino-1.0.1\libraries\Ethernet) just above where it is 
used in 

'// Check we've got a valid DNS server to use
    const IPAddress INADDR_NONE(0,0,0,0);  // These probably a more elegant way to do this but it works
    if (iDNSServer == INADDR_NONE)
    {
        return INVALID_SERVER;
    }'

Which is on lines 129-131.

This gives me back 48bytes of SRAM and incidentally makes the Sketch 200 odd 
bytes smaller!

Original comment by brucedur...@btinternet.com on 7 Mar 2013 at 4:56

GoogleCodeExporter commented 9 years ago
It does of course not matter whereto you more the definition, but if the 
declaration is in IPAddress.h then one would normally expect the definition in 
IPAddress.cpp.

Original comment by sebastia...@googlemail.com on 9 Mar 2013 at 8:22