N
Neil Zanella
Hello,
I have a file with about 1400 lines of C++ code most of which
consists of a single class. An oversimplified version of the
file is the following...
--- BEGIN ORIGINAL FILE ---
#include <iostream>
class Foo {
public:
Foo(int x): _x(x) { init(); }
private:
void init();
int _x;
};
void Foo::init() {
std::cout << "Hello, World!" << std::endl;
}
int main(void) {
Foo foo(1024);
}
--- END ORIGINAL FILE ---
I then make the following change to the file, and would expect the
output to be the same, but alas, what I see is that the code compiles
with no errors, even runs, but when it runs I get unexpected run time
errors that seem to depend on the amount of methods I add to the class
(i.e. if I add one more the whole things starts to malfunction). So
here is what I think should be equivalent, but g++ produces an
executable file that does NOT do the same thing:
--- BEGIN MODIFIED EXAMPLE ---
#include <iostream>
class Foo {
public:
Foo(int x): _x(x) { init(); }
private:
void initialize();
void init();
int _x;
};
void Foo::initialize() {
init();
}
void Foo::init() {
std::cout << "Hello, World!" << std::endl;
}
int main(void) {
Foo foo(1024);
}
--- END MODIFIED EXAMPLE ---
Now this is a trivial modification. On this small code snippet,
everything works fine, but on my 1400 line class it's not the case,
and I am using GNU g++ 3.2.2 on a Debian Linux box.
So, can anyone please provide a hint as to what the problem may be???
This must be the most obscure bug I've ever come across.
Thanks,
Neil
I have a file with about 1400 lines of C++ code most of which
consists of a single class. An oversimplified version of the
file is the following...
--- BEGIN ORIGINAL FILE ---
#include <iostream>
class Foo {
public:
Foo(int x): _x(x) { init(); }
private:
void init();
int _x;
};
void Foo::init() {
std::cout << "Hello, World!" << std::endl;
}
int main(void) {
Foo foo(1024);
}
--- END ORIGINAL FILE ---
I then make the following change to the file, and would expect the
output to be the same, but alas, what I see is that the code compiles
with no errors, even runs, but when it runs I get unexpected run time
errors that seem to depend on the amount of methods I add to the class
(i.e. if I add one more the whole things starts to malfunction). So
here is what I think should be equivalent, but g++ produces an
executable file that does NOT do the same thing:
--- BEGIN MODIFIED EXAMPLE ---
#include <iostream>
class Foo {
public:
Foo(int x): _x(x) { init(); }
private:
void initialize();
void init();
int _x;
};
void Foo::initialize() {
init();
}
void Foo::init() {
std::cout << "Hello, World!" << std::endl;
}
int main(void) {
Foo foo(1024);
}
--- END MODIFIED EXAMPLE ---
Now this is a trivial modification. On this small code snippet,
everything works fine, but on my 1400 line class it's not the case,
and I am using GNU g++ 3.2.2 on a Debian Linux box.
So, can anyone please provide a hint as to what the problem may be???
This must be the most obscure bug I've ever come across.
Thanks,
Neil