Re: [ROOT] TDataMember::GetMaxIndex() return large negative number!

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Aug 14 2000 - 18:16:32 MEST


Hi Christian,

   this will not work since CINT does not know how to associate fBar with
fBaz (the //[fBar] is only used for the Streamer generation in case of non
static data members).

Also the const data member feature (being a late addition to the C++ standard)
is not entirely portable yet accross the currently supported spectrum of
compilers.
Better is to do:

class Foo : public TObject
{
public:
  enum { kBar = 3 };
  static const char* fBaz[kBar];

  ClassDef(Foo,1) // Foo object
};


with foo.cxx:

#include "foo.h"
ClassImp(foo)
const char *foo::fBaz[] = { "Foo", "Bar", "Baz" };

and now GetMaxIndex(0) returns correctly 3.


Cheers, Fons.




Christian Holm Christensen wrote:
> 
> Hi ROOT'ers,
> 
> First some info:
> ROOT version: 2.25/01
> CINT version: 5.14.44
> OS:           Redhat Linux 6.1
> Architecture: i386 (PIII)
> 
> There seems to be a bug in "TDataMember::GetMaxIndex(int)", or maybe it's
> in int "G__DataMemberInfo::MaxIndex(int dim)", because it returns a
> large negative number for size of the index if, in my class I have
> have a static const Char_t* array of unknown size. Here's a reall
> simple example showing whats going on:
> 
> File foo.hh
> -----------------------------------------------------------------
> #ifndef FOO_H
> #define FOO_H
> 
> #include <TObject.h>
> 
> class Foo : public TObject
> {
> public:
>   static const Int_t   fBar;
>   static const Char_t* fBaz[]; //[fBar]
> 
>   ClassDef(Foo,1) // Foo object
> }
> ;
> 
> #endif
> 
> File foo.cc
> -----------------------------------------------------------------
> #include "foo.hh"
> #include <iostream>
> 
> ClassImp(Foo);
> 
> const Int_t   Foo::fBar = 3;
> const Char_t* Foo::fBaz[Foo::fBar] = { "Foo", "Bar", "Baz" };
> 
> File fooLinkDef.hh
> -----------------------------------------------------------------
> #ifndef __CINT__
> #error "Not for compiling"
> #endif
> 
> #pragma link off all classes;
> 
> #pragma link C++ class Foo;
> 
> File fooMake.sh
> -----------------------------------------------------------------
> #!/bin/sh
> 
> rootcint -f fooCint.cc -c foo.hh fooLinkDef.hh
> g++ `root-config --cflags` -g -fPIC -Wall -c fooCint.cc
> g++ `root-config --cflags` -g -fPIC -Wall -c foo.cc
> g++ -shared -Wl,-soname,libFoo.so -o libFoo.so fooCint.o foo.o
> 
> When I do:
> 
>  prompt% root
>    *******************************************
>    *                                         *
>    *        W E L C O M E  to  R O O T       *
>    *                                         *
>    *   Version   2.24/05       16 May 2000   *
>    *                                         *
>    *  You are welcome to visit our Web site  *
>    *          http://root.cern.ch            *
>    *                                         *
>    *******************************************
> 
>  Compiled with thread support.
> 
>  CINT/ROOT C/C++ Interpreter version 5.14.38, May 5 2000
>  Type ? for help. Commands must be C++ statements.
>  Enclose multiple statements between { }.
>   root [0] gSystem->Load("./libFoo.so")
>  (int)0
>  root [1] TClass* c = Foo::Class()
>  root [2] TDataMember* m = c->GetDataMember("fBaz")
>  root [3] m->GetMaxIndex(0)
>  (const Int_t)(-2147483648)
>  root [4]
> 
> To me it looks like over flow of some variable, since looking in
> /usr/include/limits.h gimme (on a i386)
> 
>   #  define INT_MIN       (-INT_MAX - 1)
>   #  define INT_MAX       2147483647
>   #   define LONG_MAX     2147483647L
>   #  define LONG_MIN      (-LONG_MAX - 1L)
> 
> The consequence of this (bug!?) is that THtml will produce a very
> large file, because of a loop inside THtml::Class2Html, that goes
> something like
> 
>   for( w = 0; w < ( maxLen2[j]-len2 ); w++ )
>     classFile << " "
> 
> where len2 = TMath::Log10(-2147483648) = nan. The file is only closed
> when it reaches the 2 GB file limit on the EXT2 filesystem.
> 
> I hope you know what's going on, 'cause I've got the faintest.
> 
> Yours,
> 
> Christian  -----------------------------------------------------------
> Holm Christensen                             Phone:  (+45) 35 35 96 91
>   Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305
>   DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm
>   Denmark                                    Email:       cholm@nbi.dk

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:31 MET