Can't compile the same C++ code on other computers including ROOT?


_ROOT Version:_ROOT 6.26/06
_Platform:_macOS Monterey
Compiler: clang


This is my makefile,
$(CXX) $(FLAGS) $(LIBS) -arch $(ARCH) -o $@ $^
where

CXX = $(shell root-config --cxx)
FLAGS = $(shell root-config --cflags) -O2 -Wall -Wextra
LIBS = $(shell root-config --libs)
ARCH = x86_64

when I run this code on my macOS, it works completely fine. I tried it on other macs that are the same model as mine and had some errors. The program does not work correctly on them. I don’t understand what the problem is. These are the errors I get:

In file included from main/functions.cpp:1:
In file included from main/essential.h:47:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TTree.h:46:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TBranch.h:29:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TBranchCacheInfo.h:25:
/opt/homebrew/Cellar/root/6.26.06_2/include/root/TBits.h:150:11: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
   return (Bool_t)lhs & rhs;
          ^~~~~~~~~~~~~~~~~
                      &&
/opt/homebrew/Cellar/root/6.26.06_2/include/root/TBits.h:150:11: note: cast one or both operands to int to silence this warning
/opt/homebrew/Cellar/root/6.26.06_2/include/root/TBits.h:155:11: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
   return (Bool_t)lhs | rhs;
          ^~~~~~~~~~~~~~~~~
                      ||
/opt/homebrew/Cellar/root/6.26.06_2/include/root/TBits.h:155:11: note: cast one or both operands to int to silence this warning
In file included from main/functions.cpp:1:
In file included from main/essential.h:50:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TCanvas.h:15:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TPad.h:15:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TVirtualPad.h:30:
In file included from /opt/homebrew/Cellar/root/6.26.06_2/include/root/TQObject.h:42:
/opt/homebrew/Cellar/root/6.26.06_2/include/root/TVirtualQConnection.h:53:42: warning: 'sizeof (val)' will return the size of the pointer, not the array itself [-Wsizeof-pointer-div]
      constexpr size_t size = sizeof(val)/sizeof(val[0]);
                              ~~~~~~~~~~~^
/opt/homebrew/Cellar/root/6.26.06_2/include/root/TVirtualQConnection.h:51:25: note: pointer 'val' declared here
   void SetArg(const T* val)
                        ^

I also downloaded ROOT via brew on my computer. Also, I had the same type of warning on a computer where the ROOT was included in a Conda env. How should I compile my code so that it could work on both Mac and Linux?

The first two warnings (“bitwise-instead-of-logical”) are fixed in newer ROOT versions.

The last warning (“sizeof-pointer-div”) looks like a real bug and is “removed” in the newest ROOT versions:

{
  double a[] = {1., 2., 3.};
  double *p = a;
  std::cout << "o.k. : " << sizeof(a) / sizeof(a[0]) << "\n";
  std::cout << "wrong: " << sizeof(p) / sizeof(p[0]) << "\n"; 
}