3 ms·
sizeof(NULL) in 4 in C++ in a 64 bit system. sizeof(NULL) is 8 in C in a 64 bit system. The difference is because NULL in C is a variable of a void pointer
by mhogomchungu 10y ago
sizeof(NULL) in 4 in C++ in a 64 bit system.
sizeof(NULL) is 8 in C in a 64 bit system.
The difference is because NULL in C is a variable of a void pointer type with a value zero. In C++,NULL is a variable with a value zero that gets deduced to an int type.
- AbacusAvenger 10y agoThat's not true. sizeof(NULL) is the same in C++ and C: https://goo.gl/WL1akj https://goo.gl/WL1akj
- mhogomchungu 10y agoI looked up at my g++ compiler and i found this: http://pastebin.com/VpSsEkBY http://pastebin.com/VpSsEkBY That g++ compiler is using a gnu extension through the __GNUG__ code path. The "true" C++ code path is at line 11. Edit: Answering the person below,the file that defines NULL is "stddef.h" An example of the file online that defines NULL is here: https://github.com/Alexpux/mingw-w64/blob/d0d7f784833bbb0b2d279310ddc6afb52fe47a46/mingw-w64-headers/crt/stddef.h https://github.com/Alexpux/mingw-w64/blob/d0d7f784833bbb0b2d...
- fnj 10y agoWhat file are we supposed to be looking at?
- fnj 10y agoI looked into this. #include <iostream> int main() { std::cout << "sizeof(NULL) = " << sizeof(NULL) << '\n'; } Compiling with both g++ 6.2.1 and clang++ 3.9.1 with -std=c++11 in both cases gives: sizeof(NULL) = 8 AFAICT, NULL should not even be defined at all in C++ 11; certainly if you include neither <stddef.h> nor <stdlib.h> nor <cstddef> nor <cstdlib>. I could never get it to compile on x86_64 linux without saying 8. Bottom line: NULL works in the execlp call, whether from C or from C++. nullptr would be cleaner.
- ben0x539 10y agofwiw, in C++11 onwards, apparently NULL is allowed to be nullptr and not an integral constant.