Hacker News new | past | comments | ask | show | jobs | submit login

This is not an anonymous structure in the modern sense (if you look at the code they are in fact named), it's a side-effect of pre-ANSI C namespace rules. Any struct field could be used to calculate an offset from any other object. From http://cm.bell-labs.com/who/dmr/chist.html :

> Beguiled by the example of PL/I, early C did not tie structure pointers firmly to the structures they pointed to, and permitted programmers to write pointer->member almost without regard to the type of pointer; such an expression was taken uncritically as a reference to a region of memory designated by the pointer, while the member name specified only an offset and a type.




I was responding to the author's general claim that "In the old days it was possible to access members of structs inside unions without having to name the intermediate struct.".

However, I stand corrected in two regards. The first is that as of gcc 4.6+, the sed example the author provided is no longer allowed even if the structs are unnamed. (I was testing with gcc 3.4.) I verified that gcc 3.4 would happily allow me to use the provided sed example as long as I removed the names from the structs.

Second, the C11 standard specifically does not allow for the sed example provided because the structs in the unions contain duplicate members.

I had seen reasoning that hinted at what you're saying in one of the comments posted on the author's blog entry.

Regardless, thanks for encouraging me to dig deeper.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: