digitalmars.D - Spec of align attribute is a mess
- Stewart Gordon (45/45) Apr 16 2009 "The great inapplicable attribute debate"
"The great inapplicable attribute debate" http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=87915 drifted into a discussion on alignment in relation to unions. However, I've looked around the spec and found that quite a bit of work is needed on the specification of align as a whole. 1. ctod.html says "Clearly, since much of the point to setting alignment is for portability of data, a portable means of expressing it is necessary." However, attribute.html says "AlignAttribute is meant for C ABI compatiblity [sic], which is not the same thing as binary compatibility across diverse platforms. For that, use packed structs:" which is basically claiming that align isn't good for portability of data after all. 2. Still on attribute.html, the basic documentation of align says "Specifies the alignment of struct members. align by itself sets it to the default, which matches the default member alignment of the companion C compiler. Integer specifies the alignment which matches the behavior of the companion C compiler when non-default alignments are used." What if the companion C compiler: - doesn't exist? - has no alignment control facilities? - has alignment control only on whole structs - IWC how should alignment applied to individual members be interpreted? - doesn't support a particular align value that's used in the D code? Moreover, if the sole purpose of align is to provide an interface to C-compiler-dependent alignment features, then this is incongruous with alignment control being given as one of D's improvements over C. It may be the case that _a standardised notation for_ alignment control is an improvement, but that's different. 3. What kind of alignment is it meant to be anyway? Absolute (based on raw memory addresses) or relative (to the beginning of the struct)? It seems that various people have assumed various answers to this. Together with the inapplicable attribute debate, this affects the logicality of the statement on attribute.html "AlignAttribute is ignored when applied to declarations that are not structs or struct members." If alignment is relative, then it's naturally inapplicable to anything that isn't a struct or a member thereof. If OTOH alignment is absolute, some attempts to use align become cases of an attribute that makes sense in the context being silently ignored. There are probably other issues with the align documentation, but I can't think of them at the mo.... Thoughts? Stewart.
Apr 16 2009