0

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:

  1. Termux in Redmi-K20-Pro Android phone (unrooted) with clang: clang++ test.cpp -o op
  2. 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:

  1. Termux printed a points at something
  2. 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?

2
  • Even if you use the Android app termux your problem is a C++ programming question which is totally unrelated to Android, and hence off-topic here. Most likely it is caused by different C++ compilers. – Robert Sep 23 '20 at 8:40
  • Assuming we're blind about the code since this site focuses on Android end-users who are not necessarily developers (Stack Overflow is for programming issue), how about compiling with GCC in Termux? – Andrew T. Sep 23 '20 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.