Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. int num_instances;
  2.  
  3. struct A
  4. {
  5.   A()
  6.   {
  7.     order = ++num_instances;
  8.   }
  9.   int order;
  10. };
  11.  
  12. A a3;
  13. A a2 __attribute__((init_priority(1000)));
  14. A a1 __attribute__((init_priority(990)));
  15.  
  16. void setup()
  17. {
  18.   Serial.begin(115200);
  19. }
  20.  
  21. void loop()
  22. {
  23.   int errors = 0;
  24.   if (a1.order != 1) {
  25.     Serial.print(F("Bad a1 order "));
  26.     Serial.println(a1.order); // This must output 1
  27.     ++errors;
  28.   }
  29.   if (a2.order != 2) {
  30.     Serial.print(F("Bad a2 order "));
  31.     Serial.println(a2.order); // This must output 2
  32.     ++errors;
  33.   }
  34.   if (a3.order != 3) {
  35.     Serial.print(F("Bad a3 order "));
  36.     Serial.println(a3.order); // This must output 3
  37.     ++errors;
  38.   }
  39.   if (!errors)
  40.     Serial.println(F("Okay!"));
  41.   delay(1000);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement