Note that there are some explanatory texts on larger screens.

plurals
  1. POC/C++: sizeof(short), sizeof(int), sizeof(long), sizeof(long long), etc... on a 32-bit machine versus on a 64-bit machine
    primarykey
    data
    text
    <p>I'm running Windows 7 (64-bit).</p> <p>This question looks at the same question found here:</p> <p><a href="https://stackoverflow.com/questions/660372/long-on-a-64-bit-machine">long on a 64 bit machine</a></p> <p>but is more in-depth as it deals with even more data types and applies to C or C++, not C#. First of all, I am using Microsoft Visual Studio Ultimate 2012. Unfortunately, while this IDE supports C# and Visual C++ it no longer supports plain old Visual C it seems. Anyhow, I've tried the creating the following standard C++ program in the IDE:</p> <pre><code>#include &lt;cstdio&gt; int main(int argc, char **argv) { printf("sizeof(short): %d\n", (int) sizeof(short)); printf("sizeof(int): %d\n", (int) sizeof(int)); printf("sizeof(long): %d\n", (int) sizeof(long)); printf("sizeof(long long): %d\n", (int) sizeof(long long)); printf("sizeof(size_t): %d\n", (int) sizeof(size_t)); printf("sizeof(void *): %d\n", (int) sizeof(void *)); printf("Hit enter to exit.\n"); char *scannedText; scanf("%s", &amp;scannedText); return 0; } </code></pre> <p>and since I couldn't find the option to run a console application I simply placed a breakpoint at the "return 0;" statement, so as to view the output in the console. The result was:</p> <pre><code>sizeof(short): %d\n", 4 sizeof(int): %d\n", 4 sizeof(long): %d\n", 4 sizeof(long long): 8 sizeof(size_t): 4 sizeof(void *): 4 Hit enter to exit. </code></pre> <p>Old C textbooks state that int is set to the "word size", which is 16 on 16-bit machines and 32 on 32-bit machines. However this rule seems to break on 64-bit systems where one would expect the "word size" to be 64. Instead, from what I've read these systems are like 32-bit systems but have better support for 64-bit computations than their 32-bit counterparts did. Hence, the results obtained from the above C++ program are exactly the same as one would obtain on a 32-bit system. The size of data types (size_t) (which can be used to measure amount of memory taken up by objects in memory) also stores its values in 4 bytes, and it is also interesting that the size of pointers used to access memory locations (for instance sizeof(void *) shows the number of bits used to store generic pointers to any location in memory) is also 32 bits long.</p> <p>Anyone know how come Visaul C was removed from Visual Studio 2012 and whether it is still possible to run console applications from Visual Studio 2012 without having to set a breakpoint or read text from standard input prior to exiting as above in order for the console window to pause before closing?</p> <p>Furthermore, is my interpretation correct, or do I have something misconfigured in the IDE so that, for instance, it compiles for 32-bit rather than for 64-bit systems? According to one of the poster, since my system is 64-bit, I should see the results described here for size_t and pointers: <a href="https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models</a> but I am not seeing this. Is there a way to reconfigure Visual Studio so that it may support a 64-bit memory model, as opposed to what I am currently seeing in the program's output?</p> <p>Thanks.</p>
    singulars
    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.
 

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