How to detect machine word size in C/C++?
<p>Is there a more-or-less reliable way (not necessarily perfect) to detect the <em>machine word size</em> of the <em>target architecture</em> for which I'm compiling?</p>

<p>By <em>machine word size</em> I mean the size of the integer accumulator register (e.g. EAX on x86, RAX on x86_64 etc., <em>not</em> streaming extensions, segment or floating-point registers).</p>

<p>The standard does not seem to provide a "machine word" data type. So I'm <em>not</em> looking for a 100% portable way, just something that works in most common cases (Intel x86 Pentium+, ARM, MIPS, PPC - that is, register-based, contemporary commodity processors).</p>

<p><code>size_t</code> and <code>uintptr_t</code> sound like good candidates (and in practice matched the register size everywhere I tested) but are of course something else and are thus not guaranteed to always do so as is already described in <a href="https://stackoverflow.com/questions/14792068/is-size-t-the-word-size">Is size_t the word size</a>.</p>

<p><strong>Context</strong></p>

<p>Let's assume I'm implementing a hashing loop over a block of contiguous data. It is OK to have the resulting hash depend on the compiler, only speed matters.</p>

<p>Example: <a href="http://rextester.com/VSANH87912" rel="noreferrer">http://rextester.com/VSANH87912</a></p>

<p>Testing on Windows shows that hashing in chunks of 64 bits is faster in 64-bit mode and in 32 bits in 32-bit mode:</p>

<pre><code>64-bit mode
int64: 55 ms
int32: 111 ms

32-bit mode
int64: 252 ms
int32: 158 ms
</code></pre>