{"action":"created","issue":{"url":"https://api.github.com/repos/me-no-dev/RasPiArduino/issues/10","labels_url":"https://api.github.com/repos/me-no-dev/RasPiArduino/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/me-no-dev/RasPiArduino/issues/10/comments","events_url":"https://api.github.com/repos/me-no-dev/RasPiArduino/issues/10/events","html_url":"https://github.com/me-no-dev/RasPiArduino/issues/10","id":123586408,"number":10,"title":"Constructors in C++ classes called before init() called","user":{"login":"nkolban","id":3421732,"avatar_url":"https://avatars.githubusercontent.com/u/3421732?v=3","gravatar_id":"","url":"https://api.github.com/users/nkolban","html_url":"https://github.com/nkolban","followers_url":"https://api.github.com/users/nkolban/followers","following_url":"https://api.github.com/users/nkolban/following{/other_user}","gists_url":"https://api.github.com/users/nkolban/gists{/gist_id}","starred_url":"https://api.github.com/users/nkolban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkolban/subscriptions","organizations_url":"https://api.github.com/users/nkolban/orgs","repos_url":"https://api.github.com/users/nkolban/repos","events_url":"https://api.github.com/users/nkolban/events{/privacy}","received_events_url":"https://api.github.com/users/nkolban/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-23T01:43:40Z","updated_at":"2015-12-23T10:58:19Z","closed_at":null,"body":"In our project, there is a method called init() which sets up the global environment including registers for the BCM2835.  If we link in a sketch, if the sketch has global variables which are instances of C++ classes then their constructors run ... which assumes the envrionment is ready .... but it isn't as the constructors run before main() is given control.\r\n\r\nFor example:\r\n```\r\nLiquidCrystal lcd(12, 11, 5, 4, 3, 2);\r\n\r\nvoid setup() {\r\n  printf(\"In setup!\\n\");\r\n  // set up the LCD's number of columns and rows:\r\n /lcd.begin(16, 2);\r\n  // Print a message to the LCD.\r\n /lcd.print(\"hello, world!\");\r\n}\r\n\r\nvoid loop() {\r\n  // set the cursor to column 0, line 1\r\n  // (note: line 1 is the second row, since counting begins with 0):\r\n  lcd.setCursor(0, 1);\r\n  // print the number of seconds since reset:\r\n  lcd.print(millis() / 1000);\r\n}\r\n```\r\n\r\nNotice the constructor at the top for the instance of the LiquidCrystal object."},"comment":{"url":"https://api.github.com/repos/me-no-dev/RasPiArduino/issues/comments/166862963","html_url":"https://github.com/me-no-dev/RasPiArduino/issues/10#issuecomment-166862963","issue_url":"https://api.github.com/repos/me-no-dev/RasPiArduino/issues/10","id":166862963,"user":{"login":"me-no-dev","id":12663778,"avatar_url":"https://avatars.githubusercontent.com/u/12663778?v=3","gravatar_id":"","url":"https://api.github.com/users/me-no-dev","html_url":"https://github.com/me-no-dev","followers_url":"https://api.github.com/users/me-no-dev/followers","following_url":"https://api.github.com/users/me-no-dev/following{/other_user}","gists_url":"https://api.github.com/users/me-no-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/me-no-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/me-no-dev/subscriptions","organizations_url":"https://api.github.com/users/me-no-dev/orgs","repos_url":"https://api.github.com/users/me-no-dev/repos","events_url":"https://api.github.com/users/me-no-dev/events{/privacy}","received_events_url":"https://api.github.com/users/me-no-dev/received_events","type":"User","site_admin":false},"created_at":"2015-12-23T10:58:19Z","updated_at":"2015-12-23T10:58:19Z","body":"yeah. That is somewhat a \"known\" limitation when running on computers\r\ni'm not really sure that the object initialization can be postponed"}}