Inferring Memory Alignment
Is there a better to do this (infer the alignment of double)?


Curious as to why size_t type is used.  The first choice should be ptrdiff_t.


  When two pointers are subtracted, ... and its type (a signed integer type) is ptrdiff_t defined in the &lt;stddef.h&gt; header.  C11dr §6.5.6 9


Since alignment is certainly something less than 127, any integer type will do for our purposes.  Could use int, unsigned, size_t.

The cast of &amp;(lSpecimen.mWedge) is redundant other than to remove the const

My GCC 4.5.3 compiler says the const on the return type is ignored.

int getDoubleAlignment(void) {
  const DoubleAligned lSpecimen;
  const int lOffset = (char*)&amp;(lSpecimen.mMember) - &amp;(lSpecimen.mWedge);
  return lOffset;
}





Under what (reasonable) circumstances could this not work?  (Nothing to add)
Under what (plausible) circumstances could this not work? (Nothing to add)





What is the actual or practical complete list of types I would need to do this with to determine universal alignment?


Rather than use double, use max_align_t if available.  max_align_t is not in C99.


  "... max_align_t which is an object type whose alignment is as great as is supported by the implementation in all contexts ..."  C11dr §7.19 2


Otherwise instead of double use a union of all non-narrow types:

union {
  int i;
  long l;
  long long ll;
  float f;
  double d;
  long double ld;
  float _Complex fc;
  double _Complex dc;
  ptrdiff_t pd;
  // Suspect the below are the only 4(5) code may truly need
  long double _Complex ldc;
  void *p;
  void (*pf)();
  intmax_t im;
  // C11
  max_align_t ma;
} OneOfEach;


void* might be narrower than void (*pf)() so void* will not work for all pointers.