g++: class size or file size limitations: NONTRIVIAL BUG

Discussion in 'C++' started by Neil Zanella, Oct 9, 2003.

  1. Neil Zanella

    Neil Zanella Guest

    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
    Neil Zanella, Oct 9, 2003
    #1
    1. Advertising

  2. Re: class size or file size limitations: NONTRIVIAL BUG

    "Neil Zanella" <> wrote in message
    news:p...
    > [...]
    > 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???


    Incorrect assumptions about the failure mode? ;>

    > This must be the most obscure bug I've ever come across.


    Perhaps the bug is not in the compiler, but in the source. ;>
    Without seeing your code, it is impossible to determine
    which. If you really think it is a compiler bug, you should
    post your code to the gcc bug list or GNATS.

    Dave



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
    David B. Held, Oct 9, 2003
    #2
    1. Advertising

  3. Neil Zanella <> writes:

    > 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...


    <snip oversimplified 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???


    I bet you are overwriting memory you aren't supposed to - e.g.
    stepping over the bounds of an array or sth like that.
    Without the real source code, it's impossible to tell - you are
    in for a really exciting debugging session :)
    You might want to check out efence or valgrind - useful tools to
    find / prevent this kind of programming error.

    HTH & kind regards
    frank

    --
    Frank Schmitt
    4SC AG phone: +49 89 700763-0
    e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
    Frank Schmitt, Oct 9, 2003
    #3
  4. Neil Zanella

    tom_usenet Guest

    On Thu, 9 Oct 2003 03:39:50 -0230, Neil Zanella <>
    wrote:

    >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,


    1400 lines is a bit long for a class. They shouldn't normally be
    longer than a few hundred lines. You should probably split the
    responsibilities of your class between several smaller ones.

    >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.


    The problem will likely be an obscure bug - an uninitialized variable,
    out of bounds array access, double deletion of a pointer or other
    undefined behaviour. The only way to find it is careful use of a
    debugger. The bug might be in code from a completely different class,
    or it might be how you are using another class.

    There is a vague possibility that it might be a compiler bug, but this
    is orders of magnitude less likely than it being a "simple" bug in
    your code.

    Tom
    tom_usenet, Oct 9, 2003
    #4
  5. Neil Zanella wrote:
    ....
    -
    >
    > 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.


    try running your code under valgrind (preferred) or efence and see what
    it says.
    Gianni Mariani, Oct 9, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Strickland

    File Upload and File Size Limitations

    Robert Strickland, Oct 29, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,633
    Lau Lei Cheong
    Nov 1, 2004
  2. GroupReader

    Are there any page size limitations?

    GroupReader, Jul 3, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    761
    GroupReader
    Jul 3, 2007
  3. glennklockwood

    total array size limitations?

    glennklockwood, Mar 13, 2009, in forum: C Programming
    Replies:
    10
    Views:
    841
  4. Michael Riedel
    Replies:
    2
    Views:
    1,331
    Michael
    Aug 27, 2009
  5. Josh Cheek
    Replies:
    7
    Views:
    102
    Josh Cheek
    Apr 10, 2010
Loading...

Share This Page