I am using mingw-w64 compiler (gcc 8.1.0) on Windows 10 (64 bit installation). My expectation is to get the maximum value of size_t
equal to (2^64 - 1). But my programs always return the value of SIZE_MAX
as (2^32 - 1 only). What could be the reason? How can i achieve the a maximum value of (2^64 - 1) in my C programs?
I am learning C language and wanted to check out the statement made in the book that on modern computers max size of size_t
can be (2^64 - 1). The piece of code I tried for checking this is as below:
#include <stdio.h>
#include <stdint.h>
int main(){
printf("%d\n", sizeof(size_t));
printf("%zu\n", SIZE_MAX);
return 0;
}
Output:
4
4294967295
I am using only one flag -std=c11
during compiling and gcc --version
returns:
gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
When checking gcc --version
you state that you get
gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
The important part of the output is this: i686-posix-dwarf-rev0
, more specifically the i686
part.
This tells us that GCC is built as a 32-bit application (i686 is a 32-bit system), and will default to creating 32-bit executables.
To build a 64-bit executable you need to add the -m64
flag.