Topic: C++ without main()


Author: Stephen Vavasis <vavasis@CS.Cornell.EDU>
Date: 1998/02/19
Raw View
Some time ago I posted a note asking whether one can write a standalone
C++ routine (no "main()") and expect it to work portably and correctly
(static data constructors called, etc.)?  Does the standard say anything
about this?  What happens to uncaught exceptions?

All of my C++ development work is writing standalone routines (no
"main") for Matlab or Tcl/Tk, often loaded by a dynamic loader and
conforming to a C calling sequence specification.  I imagine many
developers are in the same boat.  Does the standard provide guidance?

Thanks,
Steve Vavasis


[ 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: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/02/21
Raw View
In article DD0@cs.cornell.edu, Stephen Vavasis <vavasis@CS.Cornell.EDU> writes:
>Some time ago I posted a note asking whether one can write a standalone
>C++ routine (no "main()") and expect it to work portably and correctly
>(static data constructors called, etc.)?  Does the standard say anything
>about this?  What happens to uncaught exceptions?

The standard is written under the assumption of a hosted implementation.
It says in 3.6.1 "Main function". That freestanding implementations
are allowed, and whether a main function is required is implementation-
defined. Except for saying which library functions are not required
in a freestanding implementation, that's all the standard says.

Freestanding implementations are all different. If the target
system supports C++, the C++ documentation should tell you
how to ensure static constructors and destructors are run,
and what happens to uncaught exceptions. (I would expect an
uncaught exception to call terminate(), since that is what
happens if the exception propagates to main and is not caught.)

You might want to have a look at the EC++ web page. EC++ is an
informal consotium of companies (mainly Japanese) who are
interested defining common ground for C++ in embedded systems.
 http://www.caravan.net/ec2plus/

---
Steve Clamage, stephen.clamage@sun.com
---
[ 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              ]