1

I'm running Windows 7 (64-bit).

This question looks at the same question found here:

long on a 64 bit machine

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:

#include <cstdio>

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", &scannedText);

  return 0;

}

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:

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.

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.

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?

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: https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models 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?

Thanks.

Community
  • 1
  • 1
John Sonderson
  • 3,238
  • 6
  • 31
  • 45
  • 2
    Visual Studio uses the [LLP64 model](https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models) on 64-bit machines. – Adam Rosenfield Nov 21 '13 at 00:25
  • 1
    sizeof(int *) would be a good addition to your list to help understand 64 bit machines. – Charlie Burns Nov 21 '13 at 00:29
  • 9
    C support was *not* removed. What you see happening in your console app is the exact same thing that happens when you create a shortcut on your desktop to your program. Flash, bang, gone. You'll have to add the proverbial "Hit any key to continue" code. Using 8-byte integers would make 64-bit code very slow. The constraint is not the processor, it is memory. It isn't any faster in 64-bit mode. Ask only *one* question. – Hans Passant Nov 21 '13 at 00:29
  • 1
    You can't pass the result of `sizeof` (which has type `size_t`) to the `printf()` format `%d`. Use `printf("%d\n", (int)sizeof(short));` – Pascal Cuoq Nov 21 '13 at 00:36
  • 1
    int would definitely not a native size word on 8 or 12-bit microcontrollers. Also, most compilers for 64-bit architecturess have int as 32-bit – phuclv Mar 26 '14 at 08:24
  • Rather that how you have it, you should use `%u` eg: `printf("sizeof(short): %u\n", sizeof(short));` – IanNorton Jan 21 '16 at 09:23
  • [What does the C++ standard state the size of int, long type to be?](http://stackoverflow.com/q/589575/995714) – phuclv Jul 01 '16 at 06:01

1 Answers1

2

Looks right to me. In c/c++ int isn't specifically defined in terms of bit-size. When creating a project you can select a "console application". VS2012 still supports C, but they mostly lump projects into C/C++. There is a compiler option (/TC I think) which will force the compiler into C compliance. By default it will imply the language by the file extension. MS C support isn't ideal, it doesn't include stdbool.h for instance.

If you want to control the bit size of your data you can use stdint.h which contains exact width int datatypes.

Dweeberly
  • 4,668
  • 2
  • 22
  • 41
  • Yeah, it's true, it doesn't include stdbool.h, hence cannot even really be considered a standard implementation, and after all these years they have not fixed the problem. I guess their IDE is more focused on C# development. – John Sonderson Nov 23 '13 at 14:20
  • 3
    I can't speak for MS but it appears they have fixed that (very recently) see: http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/0638.Updated-Conformance-Map.png I think they for quite a while they did spend a lot of time on managed code, but over the last year they seem to be refocusing on C++. Generally you have to work with what ya got not what ya want :-) – Dweeberly Nov 23 '13 at 16:22