entry point of application

J

James Kanze

* James Kanze:
[...]
The C++ standard requires a "main" startup function with "int"
result type.
The two signatures you show above must be supported.
With Microsoft tools you may indeed have to use the linker
option you referred to above, in order to correctly have the
standard "main" startup function called by the entry point
code.
Are you sure of this. I've only used VC++ for small, test
programs, but I've all of them have a fully standard main(), and
I'm not aware of having used any special compiler options to
make them link. (I have needed special options to get them to
compile C++. Including the standard library headers. But as
far as I know, things like /GR /Ehs /vmg or whatever don't
affect the linker.)
Yes, I'm sure.
I think your experience is due to mostly writing server-like
code.

Not on Windows. All I've written on Windows are small test
programs. No servers, no GUI's, no nothing significant.
When you specify GUI subsystem (no automatic console window) the
Microsoft tools default to a different entry point that doesn't call
"main" but "WinMain". GNU tools are smart enough to pick the startup
function you provide. Microsoft's tools are not.

When you write a GUI, you're often in another world. WxWidgets
takes over main as well, or does something similar, from what I
can see. (But again, I've not much experience with it, so I've
probably missed something.)

I don't know why this should be. It seems like poor design to
me. I suspect that it dates back from the days of single
threaded code, when the windowing code had to manage the main
loop in order to catch all of its events. There's no excuse for
it in a modern, threaded system. But it is.
Well yes, sort of relevant. I didn't mention the
corresponding option for VC++ because with that option it
fails to compile Microsoft's own headers. Or at least used
to, I haven't checked lately. :)

I've found just the opposite (with my small tests, using VC++
8). If you fail to specify /Ehs, for example, you'll get tons
of errors from Microsoft's own standard headers. From my
limited experience, if you want to compile without any options,
you can't use any of the standard C++ library---which for my
small tests programs means no I/O, no arrays (std::vector), and
no character strings.
I think by "that" you're referring to the bunch of options I
listed in addition to specifying entry point.

I'm referring to a bunch of options, in general. If we're
talking about production code, no compiler works without some
options. In many ways, it couldn't: what you need for your
production code is likely different than what I need.
Well I have only limited experience with current C++
compilers, but at least with g++ you don't have to specify
that basic functionality such as "main", exceptions, RTTI,
for-loop scope and built-in wchar_t, should be supported.
It's one thing to have to up warning levels or say hey, I want
some extensions, it's quite another thing to have specify in
detail to a C++ compiler the various aspects of the standard
C++ language that you want supported.

Agreed. It's frustrating that "cl hello.cc" won't even compiler
the classical hello world program (which for C++ uses iostream,
and won't compile without /Ehs, and maybe some others). But the
problem is really limited to just those small test programs,
when you want to see how the compiler handles such and such a
construct. For your production code, one option more or less
doesn't matter (and of course, you'll have carefully gone
through the compiler documentation, and considered the relevance
of each option, regardless).
And for those unfortunate newbies using that compiler via its
associated IDE, to have to turn off features such as
Microsoft's precompiled headers that cause non-standard
behavior.

There could be a problem with the IDE, and with newbies. Since
I don't use the IDE, I couldn't say, but from what I've heard,
the "defaults" aren't really appropriate for newbies (and of
course, it will only be newbies who use the defaults).
Yes, no disagreement there!
I have no experience with language extensions for sockets. Do
they really exist?

They're library extensions, of course, but they're certainly not
part of the C++ standard.
Anyways, having to add in language extensions, or turn them
off, is as mentioned quite different from having to specify in
detail the aspects of the C++ language that you want
supported.

Agreed.

I don't know the situation with regards to the IDE, since my use
of VC++ (to date) has been limited to trying to compile code
which already worked under Solaris or Linux, from the command
line of a Unix like shell (or from GNU make). I don't think I'm
a typical user, and while I am a newbie with regards to Windows,
I sort of doubt that I'm a typical newbie even there.

My point was only that I do write code which uses main(), that
compiles without any special options to tell the compiler that
main() is the entry point. Although I do need other options
(which for very simple things, such as testing answers to
questions here, I don't need with g++ or Sun CC).
 
A

Alf P. Steinbach

* James Kanze:
My point was only that I do write code which uses main(), that
compiles without any special options to tell the compiler that
main() is the entry point. Although I do need other options
(which for very simple things, such as testing answers to
questions here, I don't need with g++ or Sun CC).

OK. With Microsoft's tools whether "main" is accepted without further
options, depends on the subsystem selected for the executable. With GNU
tools "main" works fine regardless (that is, in my experience; there may
of course be some special case also with those tools).

Cheers, & hth.,

- Alf
 
A

Alf P. Steinbach

* James Kanze:
I've found just the opposite (with my small tests, using VC++
8). If you fail to specify /Ehs, for example, you'll get tons
of errors from Microsoft's own standard headers. From my
limited experience, if you want to compile without any options,
you can't use any of the standard C++ library---which for my
small tests programs means no I/O, no arrays (std::vector), and
no character strings.

I think you meant, "I've had the very same experience".

Microsoft's option for standard conformance is called something "a" for
"ansi".

With that option extensions or at least many extensions are turned off,
and guess where the extensions are extensively used? <g>


Cheers, & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,329
Latest member
InezZ76898

Latest Threads

Top