[comp.lang.c++] cpp and _main

kelley@halley.UUCP (Michael Kelley) (12/07/90)

I've got a couple more questions.  The first concerns pre-processing:
is the text replacement for a macro containing a C++ style comment defined,
or will it vary from cpp to cpp?  That is, if I have an ostream for debugging,
named cdbg, can I do this to take out the code when not debugging:

#ifndef DEBUG
extern ostream cdbg;
#else
#define cdbg //
#endif

I'll grant you it may not be that useful, since it will only work for
expressions on one source line, but hey, I'm just curious.

The second question is about AT&T's version cfront and the initialization
performed in _main().  What would you say to passing it argc and argv,
and having it call __main()?  This new __main() would do what _main() does
now--call the initializers in the _ctors list; then developers could provide 
their own version of _main.  By publishing the name of your software's
initialization routine--say, Gifts::intialize for our Graphical Interface
For Tandem Systems, or NIH::Initialize--we could build software upon other
libraries, perform all the necessary initialization, and do so without
forcing the application developer to make all the right initialization calls.
So if our group uses NIH (we don't), then our version of _main() becomes:

void _main(int argc, char *argv[])
{
	__main();
	NIH::Initalize();
	Gifts::Initialize(argc, argv);
}

Global objects with constructors work fine for some things, but without
having the order in which they are initialized defined, and given the need
to access command-line arguments, I believe some scheme like this will be
very beneficial.  Comments?  What are other C++ implementations doing for
initialization?
-- 
Mike Kelley
Tandem Computers, Austin, TX
halley!kelley@cs.utexas.edu
(512) 244-8830

jimad@microsoft.UUCP (Jim ADCOCK) (12/15/90)

In article <1204@halley.UUCP> kelley@halley.UUCP (Michael Kelley) writes:
|
|I've got a couple more questions.  The first concerns pre-processing:
|is the text replacement for a macro containing a C++ style comment defined?

Yes, see ARM's chapter on pre-processor.

[and/]
|or will it vary from cpp to cpp?  

Yes, because today's implementations of cpp's are not very good at following
the C++ definition.  There are at least four major flavors of cpp's in 
use today.  Those following K&R, those following ANSI-C, those following
ARM, and those doing entirely their own thing.  If one wants to port
software easily today then, one would do best not to rely on fine-grained 
details of the cpp implemention.

|That is, if I have an ostream for debugging,
|named cdbg, can I do this to take out the code when not debugging:
|
|#ifndef DEBUG
|extern ostream cdbg;
|#else
|#define cdbg //
|#endif

As I understand it, in theory each comment should be converted to a single
white space at a pre-processing phase prior to macro evaluation and 
expansion.  So your cdbg line is equivalent to:

#define cdbg 

In practice, many cpps still do not recognize // as a comment, so the
behavior you get will probably vary.