Xref: utzoo comp.lang.c++:10645 comp.std.c:3999 comp.std.c++:462 Path: utzoo!utgpu!cunews!cognos!jimp From: jimp@cognos.UUCP (Jim Patterson) Newsgroups: comp.lang.c++,comp.std.c,comp.std.c++ Subject: Re: calling main in ANSI C Keywords: main standard Message-ID: <9098@cognos.UUCP> Date: 3 Dec 90 14:59:43 GMT References: <814@atcmpe.atcmp.nl> Reply-To: jimp@cognos.UUCP (Jim Patterson) Followup-To: comp.lang.c++ Organization: Cognos Inc., Ottawa, Canada Lines: 38 In article <814@atcmpe.atcmp.nl> leo@atcmp.nl (!Leo Willems) writes: >The ARM (the annotated C++ reference manual), section 3.4 states: > > "The function main() may not be called from within a program." > >I was looking for the same restriction in ANSI C, but could not find >any statement in the ANSI C standard (2.1.2.2.1). >Par. 2.1.2.2.3 (Program termination) states: > > "A return from the initial call to the main function...." > >The word "initial" suggests (to me) that main() may be called from within the >program. At least some implementations treat the function 'main' in a special manner. Here's a snippet from a listing from VAX/VMS C V3.1-051 with the "/machine_code" flag on: 146 int main(void) { 0000 main: 0000 0000 .entry main,^m<> 5E 08 C2 0002 subl2 #8,sp 00000000* EF 16 0005 jsb C$MAIN_ARGS The subroutine C$MAIN_ARGS is only called by main, and the call is generated automatically by the compiler. I believe that it's purpose is to arrange for the argc and argv parameters to be provided to the main entry point. It's my guess that if you tried to call main() with different arguments with this compiler it wouldn't work (main would get the command line arguments no matter what you did, or something worse would happen). I won't hazard a guess as to whether this is considered legitimate behaviour according to the standard. -- Jim Patterson Cognos Incorporated UUCP:uunet!mitel!cunews!cognos!jimp P.O. BOX 9707 PHONE:(613)738-1440 3755 Riverside Drive NOT a Jays fan (not even a fan) Ottawa, Ont K1G 3Z4 Brought to you by Super Global Mega Corp .com