Topic: Legal? can't get clean answer


Author: "David V. Corbin" <dcorbin@dyn-concepts.com>
Date: 1998/05/07
Raw View
class Funky
{
private:
 value;
public:
Funky(int initial) {value = initial; }
operator int() { return(value); }
};

class IsThisABug
{
public:
 IsThisABug(Funky const & init =5) {}
};

void main void
{
IsThisABug bug;
}


End/Code: It appears that with (many/all???) compilers the Funky Object
is created AND destroyed before the IsThisABug constructor executes!!!!
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Pete Becker <petebecker@acm.org>
Date: 1998/05/07
Raw View
David V. Corbin wrote:
>
> class Funky
> {
> private:
>  value;
> public:
> Funky(int initial) {value = initial; }
> operator int() { return(value); }
> };
>
> class IsThisABug
> {
> public:
>  IsThisABug(Funky const & init =5) {}
> };
>
> void main void
> {
> IsThisABug bug;
> }
>
> End/Code: It appears that with (many/all???) compilers the Funky Object
> is created AND destroyed before the IsThisABug constructor executes!!!!

 Under the "as if" rule, this program must act as if the compiler had
followed all of the language rules. Since the program has no observable
behavior, it does that. A compiler can go further and never create a
Funky object at all, and still be correct: the program would still have
no observable behavior.
 Add some code to write output from the constructor of Funky and from
the constructor of IsThisABug. Add destructors to each, and write output
from the destructors. Now you have observable behavior, and now you can
say meaningful things about the order of construction and destruction.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]