My question has been closed again (this time by my approval) and comments and votes have mostly stopped coming. It seems like the dust has settled, so I just want to post a self-answer to this post too, just to tell my final opinion and a sort of update.
The first time my question was closed, I was definitely confused. Looking back, it was possibly because some people tried my program on a different implementation/system where they got a different output (maybe because a long
is 32 bits on some systems, for example). I still find it strange that all three apparently voted to close because of the same reason, but @SteveSummit and @philipxy present some possibilities too.
In hindsight, I agree that the post should have been closed, but probably for lacking focus. I definitely wrote less than I should have, mainly because I didn't think it would be helpful (yes, bad excuse), and that I wasn't expecting this to become a lesson in pointers, so I didn't delve too deep into that kind of research. Furthermore, I was indeed phrasing my question in such a way that I was asking many questions, leaving my real question unclear. I think the question has improved a lot since then, but yes, at the time, it could have been closed for lacking focus.
Anyway, the post was reopened, I started getting a slew of downvotes and upvotes alike. At some point, I guess the downvotes mostly stopped. Comments started coming too, and there were lots. Nothing like this had ever happened to me before, very complex words were being thrown around, and I was left answering all of them to the best of my ability. People gave suggestions and I improved my post along the way. A troll came and gave a useless joke answer (thankfully it was downvoted and deleted swiftly).
Today, there were more upvotes, more comments and more edits to the post. About a few minutes ago, I got a notification asking if this question gave me the answer I wanted. The question talks a lot about undefined behavior with pointers in C. I chose to approve this and as of now, my question has been marked as a duplicate.
The main reason I approved the post (apart from the answers helping the program in my question seem somewhat more understandable) was that, on its own, I don't think this would be a very helpful post in the future. It asks a very specific question and it is unlikely someone will stumble upon this post in the future. The comments on my question and answer were very informative and talked about a lot of different things, so I didn't want that to go to waste. Now that this question is linked to the duplicate question, hopefully someone will stumble upon it and find some nice information. I was also very overwhelmed by the amount of traction my post had gained. Anyways, now it's all settled down and everything is pretty much over.
EDIT: things have changed since I posted this answer. For an update, see Lundin's post.
0x12
and12
are the same thing, its not a mis-type and its certainly reproducible, but it has the same flavor of being a trivial fix. I don't think that's the case here, even if the answer may be seen as simple once you know the trick.*(((unsigned char *) &foo) + i)
specifically.