[ROOT] preprocessor defines with egcs

From: Kristjan H Gulbrandsen (gulbrand@mit.edu)
Date: Sun May 06 2001 - 00:23:04 MEST


Hi

  PHOBOS has been trying to get their software to work with ROOT3.
While we were able to get it to compile quite a while ago, we found
problems with streaming old files in. One problem found was that
byte swapping no longer seemed to be in effect. (We are using
intel-linux with egcs-1.1.2 release.) Eventually, the problem
was found to be a combination of a change in RConfig.h between
ROOT2.25 and ROOT3.00 and a compiler flag that we use. Specifically,
ROOT2.25's RConfig.h checks for the existence of '__linux', while
ROOT3.00 checks for the existence of 'linux'. I looked through ROOT's
changelog and found that the switch was due to an observation that
only 'linux' is defined by GCC and KCC on all platforms. The problem
came about, because PHOBOS uses the -ansi flag during compilation.
Apparently (according to the gcc online documentation), predefined
macros such as 'unix' or 'linux' are incompatible with the ISO C and
ISO C++ standards, so the specification of -ansi will make these
undefined.

This is easily testable by using the following code:

#include <iostream.h>

int main()
{
#ifdef linux
  cout << "linux is defined" << endl;
#else
  cout << "linux is not defined" << endl;
#endif
}

and compiling by using just g++ and then by using g++ -ansi and
seeing what it prints out. I am writing this email to make people
aware of this issue and to ask if ROOT could do the following
check in RConfig.h:

#if defined(linux) || defined(__linux__)
or
#if defined(linux) || defined(__linux)
instead of just
#if defined(linux)

Right now PHOBOS can get around the problem since we detect this
separately with 'uname -s' (which works for us because we only use systems
that know this command), and if linux is detected, we give a -Dlinux to
g++ to define it. In any case, we would prefer if RConfig.h worked
(untouched by us) independent of the -ansi flag as suggested by the change
mentioned above.

				Thanks,

				Kris Gulbrandsen
				gulbrand@mit.edu



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:44 MET