Note that there are some explanatory texts on larger screens.

plurals
  1. POMSVC++ handling unsigned long long int
    primarykey
    data
    text
    <p>I'm having an issue with the way MSVC handles unsigned long long integers. Here's code to reproduce:</p> <pre><code>// test.cpp (note extension) #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(int argc, char **argv) { unsigned long long int address = 0x0A0B0C0D0E0F; printf("Address=%llu\n", address); printf("%02X:%02X:%02X:%02X:%02X:%02X\n", ((address &gt;&gt; (5 * 8)) &amp; 0xff), ((address &gt;&gt; (4 * 8)) &amp; 0xff), ((address &gt;&gt; (3 * 8)) &amp; 0xff), ((address &gt;&gt; (2 * 8)) &amp; 0xff), ((address &gt;&gt; (1 * 8)) &amp; 0xff), (address &amp; 0xff)); printf("%02X:", ((address &gt;&gt; (5 * 8)) &amp; 0xff)); printf("%02X:", ((address &gt;&gt; (4 * 8)) &amp; 0xff)); printf("%02X:", ((address &gt;&gt; (3 * 8)) &amp; 0xff)); printf("%02X:", ((address &gt;&gt; (2 * 8)) &amp; 0xff)); printf("%02X:", ((address &gt;&gt; (1 * 8)) &amp; 0xff)); printf("%02X\n", (address &amp; 0xff)); exit(0); } </code></pre> <p>When I compile this on linux, I get (as expected):</p> <pre><code>Address=11042563100175 0A:0B:0C:0D:0E:0F 0A:0B:0C:0D:0E:0F </code></pre> <p>However, when I compile this on MSVC++ 2008 Express I get:</p> <pre><code>Address=11042563100175 0A:00:0B:00:0C:00 0A:0B:0C:0D:0E:0F </code></pre> <p>Have I formatted my printf statement incorrectly? Or does MSVC leave an extra byte on the stack after the shift/and operations? Or is the issue with something else?</p> <p>Note: when compiling with MSVC you need to use the '.cpp' file extension to force C++ mode. I believe this is because MSVC in straight C mode does not include (all of) C99 which includes the '%llu' flag for printf.</p> <p>Simon.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload