Loading...
Pages: 1 [2]   Go Down
Author Topic: Program doing HTTP requests breaking after a while  (Read 377 times)
0 Members and 1 Guest are viewing this topic.
Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 56
Posts: 3529
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cool, zoomkat, thanks for that!

Right now the sketch is still running, which means that it has been running longer than it used to.

Good to hear! Hopefully that will cure most of your problems.  smiley

But dhunt is correct. You should avoid returning pointers to local variables like that. When the function returns, that variable declaration is no longer valid. It may work like that now, but it is counting on luck.

edit: As I recall from years ago, that type of return (or passing string variables) used to push the entire string contents into the stack, rather than return a pointer. But either way, those techniques should be avoided.
« Last Edit: February 10, 2012, 07:18:50 am by SurferTim » Logged

Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like my limited c++ experience is showing; this link talks about returning objects that are created inside functions: http://www.cplusplus.com/forum/general/7474/.

So the compiler will either copy the object out to the caller or if you're lucky it will do return code optimization and declare the object in the callers scope to avoid the copy.

So this style of return shouldn't be causing the instability unless it is copying and somehow running out of ram when it mallocs memory for the new copy.
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 56
Posts: 3529
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@dhunt: I agree with your first post. I know what compilers are capable of, but just because a compiler will attempt to compensate for your incompetence or stupidity, doesn't mean you should rely on that.

To rely on a variable that is no longer in scope is bad programming technique. But that is just me...

Logged

Pages: 1 [2]   Go Up
Print
 
Jump to: