7 ms·
Is this a "lost art"? I always consider the layout when I'm writing a C struct. It's the principal concern that governs the correct ordering of the members.
by alextingle 13y ago
Is this a "lost art"? I always consider the layout when I'm writing a C struct. It's the principal concern that governs the correct ordering of the members.
- Iftheshoefits 13y agoI was wondering that myself. This doesn't seem like a "lost art" so much as a basic necessity for even moderately constrained applications. I can't remember the last time I did not consider the layout of members of my C structs (other than toy, or proof-of-concept applications).
- deleted 13y ago[deleted]
- pandaman 13y agoFor a guy who thinks that x86 is a modern architecture and all architectures that can only do aligned memory access are "older"? I guess it is.
- derleth 13y ago> x86 is a modern architecture It's a modern ISA, implemented by modern microarchitectures.
- colin_mccabe 13y agoIf you go back to 1993, SPARC, PA-RISC, MIPS, and Alpha all seemed like serious contenders for the next big CPU architecture. To my knowledge, none of them supported unaligned access (though I'm sure someone will point out a counterexample). 20 years later, all of them are dead and x86_64 and ARM are the new "modern architectures." x86_64 supports unaligned access and ARM has been gradually gaining support for it. So yes, chips that can only do aligned memory access do tend to be older.
- pandaman 13y agoIf you go back to 1992 you will find PowerPC which is still around. Same as MIPS. Listen, I know that there are people who worked into retirement without ever seeing anything other than x86 but a) this shows how old x86 is and b) does not give them expertise over different ISAs.
- colin_mccabe 13y agoI guess MIPS and PowerPC are still around somewhere, but it's definitely a lot less common to see them these days. For example, it used to be that every Mac came with a PowerPC, and so people were aware of the issues that chip had. Nowadays it's rare to find a programmer experienced with anything but x86. That was really Eric's point when he made that comment.
- vidarh 13y agoIt's less common because they're hidden inside other equipment. E.g. my RAID cards have PPC cpu's; my set-top box used to be MIPS. They're both licensing hundreds of millions of cores a year.
- vidarh 13y agoTo nitpick about all of them being dead: MIPS is still in the top 4 or so CPU architectures by volume, with x86, PPC, and ARM, with ARM as by far the largest (forecast about 3 billion cores licensed last year). At least a few hundred million MIPS cores are shipped every year. Depending on what you think embedded x86 volume is, it may be ahead of x86. Of course by revenue x86 still beats everyone.
- userbinator 13y agoIntel actually put in an feature to trap on unaligned access starting with the 486 (and it still exists today) - look up the AC "alignment check" flag. Of course almost no one used that feature since x86 supported unaligned access from the very beginning, and I think this flexibility is one of the reasons why it's stayed competitive: lots of features initially, not all of them optimal (e.g. division instruction on the 8088 was extremely slow), then improve on them with each new microarchitecture, the result being that existing software benefits from these improvements. In contrast, an architecture that didn't support unaligned access would not do much for existing software if faster instructions for unaligned access were introduced since they wouldn't be used.
- gaius 13y agoAgreed. This is just how normal people, err, construct structs. You are not an advanced C programmer until you have grasped it. You are not a master of C until you could have written this document yourself and can criticize it intelligently In other words, a "hacker" is someone just like ESR. More blowhardery. I for one don't claim to be a master...
- hobs 13y agoTo be fair, he didn't claim that by writing this document he was a master of C, or that a master would only know this document, just that it was a piece of knowledge a master would should definitely have. Phrasing I guess.
- hdevalence 13y ago"A master of C must have the same views of what's important and the same writing style that I do" i.e., 'a hacker is someone who looks like me'.
- philh 13y agoThat is not a charitable interpretation of what he wrote. Try, "A master of C must already know about structure packing deeply enough to teach it".
- tjgq 13y agoI strongly suspect this depends on how one comes across C. In my experience, people who learn C as a first language seem to develop a much deeper intuition for these subtleties than, say, someone who has cut their chops in higher-level languages and only then progresses (regresses? :)) to C.
- stackcollision 13y agoI think this is a pretty good assessment. I learned C first, so a lot of this stuff comes naturally to me. On the other hand, a friend of mine learned Java first. Now he's in a Master's program and doing C, and he's constantly asking me about low level stuff like byte alignment.
- philh 13y agoI can read and write C, but I didn't know much about this, and I was only vaguely aware that bitfields exist.
- vanderZwan 13y agoHis definition of "lost art" can be summed up as "can't be Googled". I think that is fair, at least when it come to programming.
- ben0x539 13y agoIt's 2014, these days I'm gonna order struct members so members that logically belong together are adjacent, and spaced apart from other members!