Here is a simple C++ code named test.cpp
to detect whether a pointer is null.
#include"iostream"
using namespace std;
int main()
{
int *a;
if(a!=NULL)
cout<<"a points at something."<<endl;
else
cout<<"a is a null pointer."<<endl;
return 0;
}
I compiled it in two devices:
- Termux in Redmi-K20-Pro Android phone (unrooted) with clang:
clang++ test.cpp -o op
- gnome-terminal in Raspberry-Pi-4B with gcc:
g++ test.cpp -o op
Then I ran the program with ./op
but the results were different:
- Termux printed
a points at something
- gnome-terminal printed
a is a null pointer.
Obviously the second result is right.
Because both devices are based on ARMv8 architecture, so no hardware problem exists. There must be some problems with Termux, the compiler, the Android system root, or something else.
Is there any solution to fix this immediately?