我用的工具是CFree套了个gcc的壳,写代码的时候偶然发现,sizeof指针是字节,而long是4字节。
且跑一个malloc最大申请空间代码的测试程序得到结果是1.99g,所以说明这个程序应该还是32位的程序,
那么为什么指针的sizeof是8个字呢 ?
ringa_lee2017-04-17 15:40:46
The specific number of bytes of int long short is implement defined. The specific number depends on the compiler implementation. There is no absolute number. Only the same compiler can guarantee the same size
If you want a sizeof pointer, make sure you use sizeof(void*)
MinGW is LLP64, long is 32-bit.
Note that when you malloc, if the parameters are represented by signed int, then when you apply for 2Gb memory, you may put a number exceeding 2^31 into signed int, and the data overflow will cause malloc to fail. You should use size_t
If you are curious about how many bits your program is, you can open the task manager. There will be a *32 mark behind the 32-bit process