-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static variable - __cxa_guard_acquire and __cxa_guard_release implementation #500
Comments
declaring static variable in the loop? again and again and .... I think the proper method is:
|
Static means it is initialised the first time loop() is executed and it retains its value when loop() is called again. The advantage is that the variable has local scope in loop() rather than being global. Code above compiles OK for Arduino Uno etc but not for ESP8266. Maybe it's not supported on ESP8266, in which case note should be added to documentation page. See www.learncpp.com/cpp-tutorial/43-static-duration-variables/
|
probably You are right :) |
@hackscribble what version and OS you use? |
Arduino IDE 1.6.5 on Windows 8. esp8266 version 1.6.4-673-g8cd3697 installed through Boards manager. Board settings: Generic ESP8266 module, 80MHz, 512K, 115200. EDIT Tried removing and reinstalling via Boards Manager, and also tested on 1.6.4. Same errors. |
ok can reproduce it, only using a function is not working. no error with: void setup()
{
}
void loop()
{
static uint32_t lastMillis = 0;
lastMillis = millis();
} strange. Note code will not have same functionality. |
Thank you @Links2004 - that's a good workaround. |
Actually, the original code is flawed in that when the static is initialed you have no idea if millis has been initialized, so it should be avoided. You should use Links2004 code as the correct way to do this. |
Thanks, @Makuna. I had not thought about that before, but I see exactly what you mean. As @Links2004 pointed out, his code is not exactly the same functionality. So I think I will change to a global variable, set to millis() at the end of setup(). |
Actually the original code is fine — C++ standard guarantees that local static initializer will be called exactly once, first time the function is executed. We just need to add __cxa_guard* implementations. |
@igrr when does the timer/variables get initialized for millis? Can you guarantee this happens before this static variable is initialised? This is my point. |
In this case local static variable will be initialized the first time loop() function runs, that's what C++ standard guarantees. millis is certainly initialized before that, so that you can use it in setup()/loop(). |
because of a known bug, the declaration of DhcpClass has to be outside the EthernetClass::begin(*mac) Method. Only if it is used with DHCP this error occurs. More details: esp8266/Arduino#500
Is there a chance to get this fixed instead of implementing a workaround? Is there someone out there with the required expert knowledge? Looks like I cannot eliminate/workaround all static stuff in the library I try to port to ESP8266 (see #1498). |
push |
you don't have to set a value for static variables, besides that links2004's code is the way you should do it! |
The point is: The library (not written by me, see related #1498) I'm talking about works quite well with Atmel/AVR Arduinos. But using it with ESP8266 brings up those errors. Rewriting the library so that it works with ESP8266 (as suggestes by @Links2004), would result in rewriting the whole library (yes, it makes massive use of those static stuff. I'm also not happy with it, but that's the current fact). That's not the idea of a portable library and an "arduino-style" compatible ESP8266. So instead of working around the problem, I would really recommend solving this issue at it's root. br, |
I see your point and I agree.
I myself have walked against this error. and solved it by making that variable (which is an object in my case) global to that function. I was just pointing out though the correctness and convention of such static variable use in a function :) |
#1586 should resolve this. @tuxedo0801 could you please try this pull request with your library and see if it works? |
Thanks a lot. Will test it, but takes until start of next week.. Will report back about the result. |
Got the same issue with a Feather 32u4 from adafruit in /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp :
Moving the static before the method worked (not fan because it is an Arduino.app provided file). But also adding the flag (like the arduino IDE does) : -fno-threadsafe-statics make compilation succeed. |
Hi,I am looking for the work-arround you guys find as i am hitting the same issue.Does there is a fork of the library somewhere or little information about how to deal with this issue ? |
This is fixed since 2.2.0. |
Thanks,just to make sure i got it straight version 2.2 is for the ESP8266 arduino core ? So that mean i got the wrong version somehow and need to upgrade |
The latest version right now is 2.3.0. If you see this happening in 2.3.0, please open a new issue and post detailed steps to reproduce (example sketch, etc.). Thanks. edit: https://github.com/esp8266/Arduino#stable-version- |
Getting the following errors with the minimal test program below. Can work around by making variable global, but it would be good to fix the problem with static.
The text was updated successfully, but these errors were encountered: