{"action":"created","issue":{"url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/145","labels_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/145/labels{/name}","comments_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/145/comments","events_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/145/events","html_url":"https://github.com/bblanchon/ArduinoJson/issues/145","id":114463901,"number":145,"title":"Invalid type for array subscript","user":{"login":"hackscribble","id":7076027,"avatar_url":"https://avatars.githubusercontent.com/u/7076027?v=3","gravatar_id":"","url":"https://api.github.com/users/hackscribble","html_url":"https://github.com/hackscribble","followers_url":"https://api.github.com/users/hackscribble/followers","following_url":"https://api.github.com/users/hackscribble/following{/other_user}","gists_url":"https://api.github.com/users/hackscribble/gists{/gist_id}","starred_url":"https://api.github.com/users/hackscribble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackscribble/subscriptions","organizations_url":"https://api.github.com/users/hackscribble/orgs","repos_url":"https://api.github.com/users/hackscribble/repos","events_url":"https://api.github.com/users/hackscribble/events{/privacy}","received_events_url":"https://api.github.com/users/hackscribble/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-11-01T11:01:51Z","updated_at":"2015-11-02T15:43:15Z","closed_at":"2015-11-01T18:52:05Z","body":"I'm trying to compile the canonical example from the wiki for an Arduino Uno using Arduino IDE 1.6.5.  The compiler reports the following errors:\r\n\r\n```\r\nsketch_nov01b.ino: In function 'bool deserialize(SensorData&, const char*)':\r\nsketch_nov01b:10: error: invalid types 'const char*[const char [5]]' for array subscript\r\nsketch_nov01b:11: error: invalid types 'const char*[const char [5]]' for array subscript\r\nsketch_nov01b:12: error: invalid types 'const char*[const char [6]]' for array subscript\r\ninvalid types 'const char*[const char [5]]' for array subscript\r\n```\r\n\r\nMy program and include files are as follows.  (I moved the struct and typedef to an include file to work round the known Arduino issue with structs).\r\n\r\n```\r\n#include <ArduinoJson.h>\r\n#include \"mystruct.h\"\r\n\r\n#define SENSORDATA_JSON_SIZE (JSON_OBJECT_SIZE(3))\r\n\r\nbool deserialize(SensorData& data, const char* json)\r\n{\r\n  StaticJsonBuffer<SENSORDATA_JSON_SIZE> jsonBuffer;\r\n  JsonObject& root = jsonBuffer.parseObject(json);\r\n  data.name = json[\"name\"];\r\n  data.time = json[\"time\"];\r\n  data.value = json[\"value\"];\r\n  return root.success();\r\n}\r\n\r\nvoid setup()\r\n{\r\n  char json[] = \"{\\\"name\\\":\\\"Ray\\\",\\\"time\\\":12345,\\\"value\\\":3.14159}\";\r\n  SensorData myData;\r\n  deserialize(myData, json);\r\n}\r\n\r\nvoid loop()\r\n{\r\n  \r\n}\r\n```\r\n\r\n```\r\nstruct sensorData\r\n{\r\n  const char* name;\r\n  int time;\r\n  float value;\r\n};\r\n\r\ntypedef struct sensorData SensorData;\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/comments/153057395","html_url":"https://github.com/bblanchon/ArduinoJson/issues/145#issuecomment-153057395","issue_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/145","id":153057395,"user":{"login":"bblanchon","id":5462433,"avatar_url":"https://avatars.githubusercontent.com/u/5462433?v=3","gravatar_id":"","url":"https://api.github.com/users/bblanchon","html_url":"https://github.com/bblanchon","followers_url":"https://api.github.com/users/bblanchon/followers","following_url":"https://api.github.com/users/bblanchon/following{/other_user}","gists_url":"https://api.github.com/users/bblanchon/gists{/gist_id}","starred_url":"https://api.github.com/users/bblanchon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bblanchon/subscriptions","organizations_url":"https://api.github.com/users/bblanchon/orgs","repos_url":"https://api.github.com/users/bblanchon/repos","events_url":"https://api.github.com/users/bblanchon/events{/privacy}","received_events_url":"https://api.github.com/users/bblanchon/received_events","type":"User","site_admin":false},"created_at":"2015-11-02T15:43:15Z","updated_at":"2015-11-02T15:43:15Z","body":"I found the problem.\r\n\r\nWhen Arduino preprocess the file, it **incorrectly** inserts function declarations before the `struct` definition.\r\nHere is the sources file that has been generated on my `tmp` folder:\r\n\r\n```c++\r\n#include <ArduinoJson.h>\r\n#include \"Arduino.h\"\r\nbool deserialize(SensorData& data, char* json);\r\nvoid serialize(const SensorData& data, char* json, size_t maxSize);\r\nvoid setup();\r\nvoid loop();\r\n#line 9\r\ntypedef struct {\r\n   const char* name;\r\n   int time;\r\n   float value;\r\n} SensorData;\r\n\r\netc....\r\n```\r\n\r\nIndeed, `SensorData` is not declared when `deserialize()` is declared.\r\nAdding `struct` acts as a forward declaration which fixes the problem.\r\n\r\nBut that just a workaround for this particular case. We need to find a more general solution or open an issue in Arduino's bug tracker."}}