Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Puzzle: make new compilers understand what g++ 2.95.3 compiled

Reply
Thread Tools

Puzzle: make new compilers understand what g++ 2.95.3 compiled

 
 
nospam_news@wanano.net
Guest
Posts: n/a
 
      05-08-2007
When language changes make old code uncompilable, that's not what is
called protection of investment.

New compilers (g++ > 3.2.3) reject classes where methods throw the
class they belong to.
gcc 2.95.3 allowed it.

What are the minimal modification, that leave the usage of the class
sound and can be compiled by newer compilers.

Thank you


( compile the following code with s.th. like g++ -g -o Exception
Exception.cpp -lstlport_gcc )

#include "iostream"

class Exception {
public:
Exception(int);
void setErrNo(int i) throw(Exception);
int errNo;
};

Exception::Exception(int e) {
errNo=e;
}

void Exception::setErrNo(int i) throw(Exception) {
auto Exception methodException(2);
errNo=i;
throw(methodException);
};

int main(char argc, char *argv[], char *env[]) {
try {
auto Exception mainException(1);
mainException.setErrNo(42);
} catch (Exception caughtmainException) {
std::cout << "caught mainException:" << mainException.errNo <<
std::endl;
}
}

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      05-08-2007
On 8 Maj, 12:57, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:
> When language changes make old code uncompilable, that's not what is
> called protection of investment.
>
> New compilers (g++ > 3.2.3) reject classes where methods throw the
> class they belong to.
> gcc 2.95.3 allowed it.
>
> What are the minimal modification, that leave the usage of the class
> sound and can be compiled by newer compilers.
>
> Thank you
>
> ( compile the following code with s.th. like g++ -g -o Exception
> Exception.cpp -lstlport_gcc )
>
> #include "iostream"
>
> class Exception {
> public:
> Exception(int);
> void setErrNo(int i) throw(Exception);
> int errNo;
>
> };
>
> Exception::Exception(int e) {
> errNo=e;
>
> }
>
> void Exception::setErrNo(int i) throw(Exception) {
> auto Exception methodException(2);
> errNo=i;
> throw(methodException);
>
> };
>
> int main(char argc, char *argv[], char *env[]) {
> try {
> auto Exception mainException(1);
> mainException.setErrNo(42);
> } catch (Exception caughtmainException) {
> std::cout << "caught mainException:" << mainException.errNo <<
> std::endl;
> }
> }


mainException is no longer in scope when you try to print errNo, are
you sure you didn't mean

td::cout << "caught mainException:" << caughtmainException.errNo <<
std::endl;

--
Erik Wikström

 
Reply With Quote
 
 
 
 
nospam_news@wanano.net
Guest
Posts: n/a
 
      05-08-2007
You are absolutely right.
This should be corrected in the initial message.

But that is not the real problem.

Thank you for your attention

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Strange array access in two executables compiled with different compilers Juha Nieminen C++ 3 09-21-2012 08:17 PM
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander ASP .Net 5 03-05-2008 04:34 PM
Puzzle: make new compilers understand what g++ 2.95.3 compiled nospam_news@wanano.net C++ 5 05-08-2007 09:39 PM
commercial c compilers vs free c compilers geletine C Programming 33 07-07-2006 05:21 AM
g++ compiled C++ code called from gcc compiled C code Klaus Schneider C++ 1 12-02-2004 01:44 PM



Advertisments