{"action":"created","issue":{"url":"https://api.github.com/repos/kripken/emscripten/issues/3301","labels_url":"https://api.github.com/repos/kripken/emscripten/issues/3301/labels{/name}","comments_url":"https://api.github.com/repos/kripken/emscripten/issues/3301/comments","events_url":"https://api.github.com/repos/kripken/emscripten/issues/3301/events","html_url":"https://github.com/kripken/emscripten/issues/3301","id":65935737,"number":3301,"title":"Glitch in structure members access","user":{"login":"Olivier-myriad","id":11772212,"avatar_url":"https://avatars.githubusercontent.com/u/11772212?v=3","gravatar_id":"","url":"https://api.github.com/users/Olivier-myriad","html_url":"https://github.com/Olivier-myriad","followers_url":"https://api.github.com/users/Olivier-myriad/followers","following_url":"https://api.github.com/users/Olivier-myriad/following{/other_user}","gists_url":"https://api.github.com/users/Olivier-myriad/gists{/gist_id}","starred_url":"https://api.github.com/users/Olivier-myriad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Olivier-myriad/subscriptions","organizations_url":"https://api.github.com/users/Olivier-myriad/orgs","repos_url":"https://api.github.com/users/Olivier-myriad/repos","events_url":"https://api.github.com/users/Olivier-myriad/events{/privacy}","received_events_url":"https://api.github.com/users/Olivier-myriad/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-04-02T14:12:11Z","updated_at":"2015-04-03T16:57:34Z","closed_at":"2015-04-02T14:19:15Z","body":"Hi,\r\n\r\nAfter trying \"Hello world\", I decided to give a shot with a more complex project.\r\n\r\nI then got an issue that I can reproduce each time, but is too embedded in my project (20 plain-C source files) to be extracted. \r\n\r\nHere is what I get, after working on some data structure:\r\nA function sets masque->lettres.items (unsigned long) to 1.\r\nThen, I have :\r\n\r\n`printf(\"Addr %08lx size %d content %lu\\n\",`\r\n`   (long)&(masque->lettres.items),`\r\n`   sizeof(masque->lettres.items),`\r\n`   masque->lettres.items);`\r\n\r\n`printf(\"Memory at %08lx = %lu\\n\",`\r\n`     (long)&(masque->lettres.items),`\r\n`     *(unsigned long *)&(masque->lettres.items));`\r\n\r\nWhatever I did before, the content of memory should be equal to the structure member. Hence, the output is :\r\n\r\n`Addr 005bdcf6 size 4 content 1703936`\r\n`Memory at 005bdcf6 = 1`\r\n\r\nHow can it be explained otherwise than an error in the Emscripten compiler?\r\n\r\nNote : I compiled my whole project using the -g4 option, as well as -s ALLOW_MEMORY_GROWTH=1.\r\n\r\nDoes anybody have a clue?\r\n\r\nThanks,\r\n"},"comment":{"url":"https://api.github.com/repos/kripken/emscripten/issues/comments/89353654","html_url":"https://github.com/kripken/emscripten/issues/3301#issuecomment-89353654","issue_url":"https://api.github.com/repos/kripken/emscripten/issues/3301","id":89353654,"user":{"login":"sunfishcode","id":4503403,"avatar_url":"https://avatars.githubusercontent.com/u/4503403?v=3","gravatar_id":"","url":"https://api.github.com/users/sunfishcode","html_url":"https://github.com/sunfishcode","followers_url":"https://api.github.com/users/sunfishcode/followers","following_url":"https://api.github.com/users/sunfishcode/following{/other_user}","gists_url":"https://api.github.com/users/sunfishcode/gists{/gist_id}","starred_url":"https://api.github.com/users/sunfishcode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sunfishcode/subscriptions","organizations_url":"https://api.github.com/users/sunfishcode/orgs","repos_url":"https://api.github.com/users/sunfishcode/repos","events_url":"https://api.github.com/users/sunfishcode/events{/privacy}","received_events_url":"https://api.github.com/users/sunfishcode/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T16:57:34Z","updated_at":"2015-04-03T16:57:34Z","body":"In plain C, longs cannot be read or written as longs on unaligned boudaries under any circumstances.\r\n\r\n#pragma pack is an extension which allows for unaligned accesses. Direct accesses to packed members are covered by the extension. But, if you take the address of a packed member, the resulting pointer is just a normal pointer, subject to the normal rules for normal pointers, including alignment.\r\n\r\nThe example code here invokes undefined behavior, meaning \"demons may fly out your nose\" at any time, even if that's not what usually seems to happen in practice.\r\n\r\nThere are tools which can help detect such problems, such as those mentioned above."}}