"BCS" <[email protected]> wrote in message news:[email protected]... > Hello aJ, > >>> In D, both type size and alignment have the same defaults on all >>> platforms. >>> >> That must be some kind of magic considering that only some platforms >> require alignment on certain (word, dword, etc.) boundaries. > > OK scratch alignment, I don't know what I was thinking there. >> >>> If desired, alignment can be explicitly controlled with the align >>> attribute. Similarly, use of specific types control sizes. >>> >> Tell me, in D, can I have all the members of the following struct be >> byte-aligned and still access and use the members directly on all >> platforms without some kind of "seqfault"(?): > > Clearly if your CPU doesn't like to unaligned reads you are going to have > problems with unaligned data members. In that cases you have several > options: > > 1) if you don't really care much about the offsets, let DMD do it's thing > 2) if you must have some given offsets, force it with align and live with > the results because you're sunk > 3) if you just need the same offset on a set of know systems, manually > find something that works and force that with align (no compiler could > help you here unless it know about all the system you care about) > 4) if you just need the same offset on all system and you don't know what > system will be used, see 2 because you're sunk. >
As I thought, I want hardware standardization. Save for hell freezing over, #3 is what I do (and catch a lot of flak for also). >> So did I just "summarize" the extent to which guaranteed basic type >> widths can be exploited, in that the design of ABC is always a "no no" >> and the design of CDE is very likely to work reliably across a wide >> range of designated platforms? >> > > I'm not very up on these issues but in short, you can let DMD do it's > thing and get good result on any given system or you can force some > alignment and get binary compatibility across systems. This is the same as > in C. What D gives you (or takes away) is issues about int being one size > on one system and another size of a different system. Understood.
