cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/20/12:53:03

From: Laurence Withers <lwithers AT lwithers DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Issues with 'gxx -O -fomit-frame-pointer' and exceptions?
Date: Sat, 20 Nov 1999 16:47:16 +0000
Message-ID: <e$yOxAAUCtN4EAR0@lwithers.demon.co.uk>
NNTP-Posting-Host: lwithers.demon.co.uk
X-NNTP-Posting-Host: lwithers.demon.co.uk:194.222.80.1
X-Trace: news.demon.co.uk 943116503 nnrp-01:1172 NO-IDENT lwithers.demon.co.uk:194.222.80.1
X-Complaints-To: abuse AT demon DOT net
MIME-Version: 1.0
X-Newsreader: Turnpike (32) Version 4.01 <WCcCG$mmNL32sYSf46vBeC80CR>
Lines: 54
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

I have come across something I don't understand when compiling code.
Whilst writing a small utility, I found that if you catch a C++
exception in main() and then return, the program will crash if you have
compiled it with the options '-O -fomit-frame-pointer' (that's -O, -O2
or -O3).

'gcc -v':

  Reading specs from c:/bin/djgpp/lib/specs
  gcc version 2.95 19990728 (release)

- sample program -------------------------------------------------------
#include <iostream>

class Exception { };

int main()
{
    try {
        char c = 0;
        cout << "Throw exception [yY]? ";
        cin.get(c);
        if(c == 'y' || c == 'Y') {
            cout << "Throwing..." << endl;
            throw Exception();
        }
        cout << "No exception..." << endl;
    }
    catch(...) {
        cout << "Exception caught..." << endl;
        return -1;
    }
    cout << "No error." << endl;
    return 0;
}
- end ------------------------------------------------------------------

Try compiling with 'gcc -O -fomit-frame-pointer -g -o test.exe test.cpp'
and then running. If you enter y or Y, the exception will be caught but
the program will crash. Any other key, and there is no crash.

Now compile without -fomit-frame-pointer, and there is no crash. Compile
without -O, and there is no crash.

Well - if anybody has any idea as to what I've done wrong, please let me
know. Otherwise, I'll compile without -fomit-frame-pointer, since I
don't suppose it provides too much of an optimisation.

Thanks for your time, and bye for now,
-- 
Laurence Withers, lwithers AT lwithers DOT demon DOT co DOT uk
                http://www.lwithers.demon.co.uk/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019