3

Having read Difference between long and int data types and Long Vs. Int C/C++ - What's The Point?

i'm trying to generate outputs of sizeof(int) and sizeof(long) by creating a 32 bit exe and a 64 bit exe.

I'm using visual studio 2010 on Windows 7 ultimate x64 SP1 and have selected x64 in the configuration manager. My pre-processor is also set to WIN64. However, i still get the sizeof(int) and sizeof(long) as 4 bytes, no matter whether i create a 32 bit exe or a 64 one.

Is there some other compiler flag that i need to set to generate a x64 exe (I cannot see the generated exe in x64/Debug folder of my project)

Community
  • 1
  • 1
user720694
  • 2,035
  • 6
  • 35
  • 57
  • 6
    The size of a long is unrelated to the processor capability. In Visual c++, a long is 4 bytes. – Joe Jul 17 '13 at 16:44
  • 3
    Agner's [Calling Conventions](http://www.agner.org/optimize/calling_conventions.pdf) contains a table of the sizes of different types in different platforms. For windows `long` is 4 bytes as `int`, both in 32 and 64bit architectures – David Rodríguez - dribeas Jul 17 '13 at 16:46
  • I think page 22 explains everything fine. http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf –  Jul 17 '13 at 16:57
  • Related: http://stackoverflow.com/questions/4329777/is-long-guaranteed-to-be-at-least-32-bits – John Dibling Jul 17 '13 at 17:06
  • @DavidRodríguez-dribeas: For _Visual Studio_ `long` is 4 bytes. I believe G++ on Windows uses an 8 byte `long` type. – Mooing Duck Jul 17 '13 at 17:10
  • Your expectation of what should happen is quite reasonable, and is what would happen in the ILP64 model. Visual C++ compilers don't use that model though. Read [**this**](http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models). – user541686 Jul 17 '13 at 17:11
  • I'm amused that the first link in this question says "both `sizeof(int)` and `sizeof(long)` return 4" and "most compilers for these platforms use a 32 bit int which has the same size and representation as a long." Did he not read the pages he linked to? Second link says "a long in C/C++ is the same length as an int." – Mooing Duck Jul 17 '13 at 17:13
  • 5
    Microsoft explicitly chose an LLP64 model. The [Raymond Chen blog post](http://blogs.msdn.com/b/oldnewthing/archive/2005/01/31/363790.aspx) hints as to the why. Any conforming compiler on the platform really has to keep to this model, otherwise they will produce non-working code. Only pointers were extended to 64bit, and the `long long` data type is used for 64bit integer representations. – Anya Shenanigans Jul 17 '13 at 17:27
  • There are two unrelated questions here. One is about `sizeof(int)` and the other is about setting compiler flags. The first one is more or less answered. As for the second one, you need to open the [configuration manager](http://siddhantahuja.files.wordpress.com/2011/07/new-configuration-manager.png), make sure you have an x64 configuration, set your project for that configuration to use the x64 platform, and off you go. – n. m. could be an AI Jul 17 '13 at 18:26
  • @Layne: That explains the requirements of the C standard; the question is about a specific implementation. – Keith Thompson Jul 17 '13 at 18:36

0 Answers0