{"action":"created","issue":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/942","labels_url":"https://api.github.com/repos/esp8266/Arduino/issues/942/labels{/name}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/942/comments","events_url":"https://api.github.com/repos/esp8266/Arduino/issues/942/events","html_url":"https://github.com/esp8266/Arduino/issues/942","id":114264374,"number":942,"title":"Weird behaviour with EEPROM.begin()","user":{"login":"marvinroger","id":990773,"avatar_url":"https://avatars.githubusercontent.com/u/990773?v=3","gravatar_id":"","url":"https://api.github.com/users/marvinroger","html_url":"https://github.com/marvinroger","followers_url":"https://api.github.com/users/marvinroger/followers","following_url":"https://api.github.com/users/marvinroger/following{/other_user}","gists_url":"https://api.github.com/users/marvinroger/gists{/gist_id}","starred_url":"https://api.github.com/users/marvinroger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marvinroger/subscriptions","organizations_url":"https://api.github.com/users/marvinroger/orgs","repos_url":"https://api.github.com/users/marvinroger/repos","events_url":"https://api.github.com/users/marvinroger/events{/privacy}","received_events_url":"https://api.github.com/users/marvinroger/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-30T12:57:52Z","updated_at":"2015-10-30T13:17:19Z","closed_at":null,"body":"I would like to call `EEPROM.begin()` with the exact amount of storage needed to save memory.\r\nI want to `put` a struct composed of:\r\n\r\n- 1 `boolean` (1 byte)\r\n- 1 `byte` (1 byte)\r\n- 5 `char[33]` (165 bytes)\r\n- 1 `unsigned int` (4 bytes)\r\n- for a total of 1 + 1 + 165 + 4 = 171 bytes\r\n\r\nSo calling `begin` with 171 should be okay. But it's not. It does not crash or anything, it just seems the data doesn't get written. But calling it with at least 173 does work.\r\n\r\nHere is the test code:\r\n\r\n```cpp\r\n#include <Arduino.h>\r\n#include <EEPROM.h>\r\n\r\nconst int EEPROM_OFFSET = 0;\r\nconst int EEPROM_OFFSET_SETUP = EEPROM_OFFSET;\r\nconst int EEPROM_LENGTH_SETUP = 1;\r\nconst int EEPROM_OFFSET_BOOT_TYPE = EEPROM_OFFSET_SETUP + EEPROM_LENGTH_SETUP;\r\nconst int EEPROM_LENGTH_BOOT_TYPE = 1;\r\nconst int EEPROM_OFFSET_HOSTNAME = EEPROM_OFFSET_BOOT_TYPE + EEPROM_LENGTH_BOOT_TYPE;\r\nconst int EEPROM_LENGTH_HOSTNAME = 32 + 1;\r\nconst int EEPROM_OFFSET_WIFI_SSID = EEPROM_OFFSET_HOSTNAME + EEPROM_LENGTH_HOSTNAME;\r\nconst int EEPROM_LENGTH_WIFI_SSID = 32 + 1;\r\nconst int EEPROM_OFFSET_WIFI_PASSWORD = EEPROM_OFFSET_WIFI_SSID + EEPROM_LENGTH_WIFI_SSID;\r\nconst int EEPROM_LENGTH_WIFI_PASSWORD = 32 + 1;\r\nconst int EEPROM_OFFSET_MQTT_HOST = EEPROM_OFFSET_WIFI_PASSWORD + EEPROM_LENGTH_WIFI_PASSWORD;\r\nconst int EEPROM_LENGTH_MQTT_HOST = 32 + 1;\r\nconst int EEPROM_OFFSET_MQTT_PORT = EEPROM_OFFSET_MQTT_HOST + EEPROM_LENGTH_MQTT_HOST;\r\nconst int EEPROM_LENGTH_MQTT_PORT = 4;\r\nconst int EEPROM_OFFSET_MQTT_BASE_TOPIC = EEPROM_OFFSET_MQTT_PORT + EEPROM_LENGTH_MQTT_PORT;\r\nconst int EEPROM_LENGTH_MQTT_BASE_TOPIC = 32 + 1;\r\nconst int EEPROM_SIZE = EEPROM_OFFSET_MQTT_BASE_TOPIC + EEPROM_LENGTH_MQTT_BASE_TOPIC;\r\n\r\nenum BootType : byte {\r\n  NORMAL = 1,\r\n  CONFIG = 2\r\n};\r\n\r\nstruct ConfigStruct {\r\n  bool configured;\r\n  BootType boot_type;\r\n  char hostname[EEPROM_LENGTH_HOSTNAME];\r\n  char wifi_ssid[EEPROM_LENGTH_WIFI_SSID];\r\n  char wifi_password[EEPROM_LENGTH_WIFI_PASSWORD];\r\n  char mqtt_host[EEPROM_LENGTH_MQTT_HOST];\r\n  unsigned int mqtt_port;\r\n  char mqtt_base_topic[EEPROM_LENGTH_MQTT_BASE_TOPIC];\r\n};\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  Serial.print(\"EEPROM of \");\r\n  Serial.print(EEPROM_SIZE);\r\n  Serial.println(\" bytes\");\r\n  EEPROM.begin(EEPROM_SIZE);\r\n  \r\n  ConfigStruct config;\r\n  config.configured = true;\r\n  \r\n  EEPROM.put(EEPROM_OFFSET, config);\r\n  EEPROM.commit();\r\n\r\n  ConfigStruct config_read;\r\n  EEPROM.get(EEPROM_OFFSET, config_read);\r\n  if (config_read.configured) {\r\n    Serial.println(\"OK\");\r\n  } else {\r\n    Serial.println(\"Not OK\");\r\n  }\r\n}\r\n\r\nvoid loop() {\r\n  \r\n}\r\n```\r\n\r\nMaybe i've made a mistake somewhere, but I just don't understand what happens.\r\nThanks."},"comment":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/comments/152520659","html_url":"https://github.com/esp8266/Arduino/issues/942#issuecomment-152520659","issue_url":"https://api.github.com/repos/esp8266/Arduino/issues/942","id":152520659,"user":{"login":"marvinroger","id":990773,"avatar_url":"https://avatars.githubusercontent.com/u/990773?v=3","gravatar_id":"","url":"https://api.github.com/users/marvinroger","html_url":"https://github.com/marvinroger","followers_url":"https://api.github.com/users/marvinroger/followers","following_url":"https://api.github.com/users/marvinroger/following{/other_user}","gists_url":"https://api.github.com/users/marvinroger/gists{/gist_id}","starred_url":"https://api.github.com/users/marvinroger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marvinroger/subscriptions","organizations_url":"https://api.github.com/users/marvinroger/orgs","repos_url":"https://api.github.com/users/marvinroger/repos","events_url":"https://api.github.com/users/marvinroger/events{/privacy}","received_events_url":"https://api.github.com/users/marvinroger/received_events","type":"User","site_admin":false},"created_at":"2015-10-30T13:17:19Z","updated_at":"2015-10-30T13:17:19Z","body":"Oh, I see. That's why the minimum for begin is 4.\r\n\r\nI am using the latest staging package. If I call begin with 171 `(EEPROM_SIZE + 3) & (~3)` does return 172, but still it doesn't work. If I call begin with 173, `(EEPROM_SIZE + 3) & (~3)` returns 176 and then it works.\r\n\r\nForget what I said, `sizeof(ConfigStruct)` returns 176... Why? Is there an overhead of the Struct?"}}