Article View: comp.std.c++
Article #3350RE: Portability. Modules. WAS: RE: Are all Windows programs ill-formed?
From: Eugene Lazutkin
Date: Tue, 20 Feb 1996 07:20
Date: Tue, 20 Feb 1996 07:20
102 lines
5813 bytes
5813 bytes
On Tuesday, February 13, 1996 9:51 AM, JdeBP@jba.co.uk
(Jonathan de Boyne Pollard) wrote:
> Eugene Lazutkin (eugene@int.com) wrote:
> | On Tuesday, February 06, 1996 9:18 PM,
> | About the main() function. A Windows compiler (MS, Borland, Symantec,
> | Watcom) doesn't check its presence. Linker does. It knows the name of
> | an entry point.
>
> Not entirely correct. One of the compilers that you mention (Borland)
> emits additional code when it encounters the definition of `main'. See
> Borland's library source for details.
>
> | You may think that main() is buried in the standard Windows
> | library and it will call WinMain(). That's it, you use the main()
> | implicitly.
>
> Again, this is not in fact true, and part of the problem that the original
> poster was pointing out. The startup code in most Windows compilers calls
> WinMain directly. There is no `main' function anywhere in the program at
> all.
I don't care about the actual implementation. Virtually there is a main().
I know that all my static constructors will be executed BEFORE main(),
WinMain() or any other head procedure. It is important. It doesn't make
any difference for me whether or not main() is the first called subroutine.
In fact, in most cases it is not true. Almost all platforms call some
stub before your main().
> | BTW, the same can be applied to the Unix (MacOS) platform. X-based
> | (Motif-based, Fresco-based,...) program are not portable either unless
> | you have the specific GUI implementation for your target platforms.
>
> Not so. If we are expanding the discussion to other platforms, you will
> find that many other platforms do not demand that programs be ill-formed
> (as a program lacking any definition of `main' surely is).
You can call a main() from the WinMain(). You can put this stub into your
default library. You can ask Bill Gates to do that for all VC++ customers.
Does it make anybody happy? I don't think so. (No offence, but it doesn't
seem to me as an important issue. Maybe MS should change their
implementation?)
> I don't remember about X offhand, but OS/2 Presentation Manager does not
> require non-standard startup procedures. The PM API is, as far as the
> applications programmer is concerned, just another function library in a
> DLL, and OS/2 PM programs start with `int main(int, char **)' just the same
> as text-mode programs do.
I'm happy for OS/2 programmers. I really am! :-) I still think that PM API
makes programs unportable. And the exact signature of the head function
helps a little. I think that the biggest problems will be to map all PM
procedures to their equvalents. From my experience, sometimes you have
to redesign a few important parts of the program. And main() is a minor
issue.
> And *this* is the issue at hand, not whether the APIs are portable. Most
> APIs appear as "just another function library" to the applications
> programmer, and portability or otherwise of libraries is not an issue with
> the C++ language itself. The issue with the C++ language is that `main' is
> the defined start procedure of *any* C++ program (sauf constructors of
> objects at global namespace scope with static storage duration), and
> Windows programs are *forced* to *not* use `main'.
See above. You can do that with less-than-10-lines stub. IMHO, C++ language
doesn't care about the name of functions. But run-time system do. Standard
tries to define the behavior of the active executable environment.
> Of course, as I've said before, the simple solution is to fix
> [basic.start.main] to allow
>
> int main ( HINSTANCE, HINSTANCE, char *, int ) { /*...*/ }
>
> as a legal definition of `main' (my proposal is for the implementation to
> define a set of legal function types for the definition of `main', which at
> minimum must contain `int main()' and `int main(int, char**)'). Then
> compiler vendors targetting DOS+Windows who wish to claim conformance can do
> so by allowing their compilers to recognise the above function definition.
I'm not a pro in a standardization, but I think that this solution
looks like a patch for MS Windows(TM). What if totally graphical
environment doesn't support any parameters or these parameters aren't a
text? This is a Unix heritage (and useful one :-) ). What does
HINSTANCE mean for ABCDOS? What if all this four parameters don't make
any sense at all for particular OS? E.g., Win32 doesn't use the second
HINSTANCE. I don't speak about future OSes.
It seems to me that we can specify the order of execution but we don't have to
dictate the real-world solutions. To me "void main()" works just fine. If
you want to obtain some shell-specific information or OS-specific data,
use custom functions. In simple cases "int main( int, const char** )"
is suitable too.
Eugene Lazutkin
eugene@int.com
---
[ To submit articles: try just posting with your news-reader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Technical Details
Message-ID:
<UPMAIL04.199602192354270852@msn.com>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backShow Full Headers
Complete Article Headers
From: "Eugene Lazutkin" <INT@msn.com> Message-ID: <UPMAIL04.199602192354270852@msn.com> X-Original-Date: Mon, 19 Feb 96 23:48:22 UT Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 20 Feb 96 07:20:29 GMT Approved: fjh@cs.mu.oz.au Organization: - Newsgroups: comp.std.c++ Subject: RE: Portability. Modules. WAS: RE: Are all Windows programs ill-formed? X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMSl2ieEDnX0m9pzZAQHsSgF9F9s0YCtd431gZz2Zr+fHgV8bXuQmgOhH Qh+TaR8I18R5tj9aa/y99nvpmUoDyoPG =LUzt