This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Sequence matters! GCC bug?



(Static members of the base class should always be inititialed first by
the *compiler*! -- not by the *programmer* on command-line -- I hope.)

$ g++ b.cpp a.cpp main.cpp -o main 
$ ./main
$
$ g++ a.cpp b.cpp main.cpp -o main 
$ ./main
Segmentation fault (core dumped)
$
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
$

Here is the files:

--- File: a.h -------------------------------------------------------------
#ifndef A_H                                                                     
#define A_H

class A{ 
public: static int* a;
};

#endif
---------------------------------------------------------------------------

--- File: a.cpp -----------------------------------------------------------
#include "a.h"

int* A::a = new int[3];
---------------------------------------------------------------------------

--- File: b.h -------------------------------------------------------------
#ifndef B_H                                                                     
#define B_H
#include "a.h"

class B: public A{
public:
static int b;
};

#endif
---------------------------------------------------------------------------

--- File: a.cpp -----------------------------------------------------------
#include "b.h"

int B::b = B::a[0];
---------------------------------------------------------------------------

--- File: main.cpp --------------------------------------------------------
#include "a.h"
#include "b.h"

int main()
{
    B* b;

    b = new B();
    return 0;
}
---------------------------------------------------------------------------




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]