Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: IBM RT compiler weirdness Message-ID: <8258@mimsy.UUCP> Date: Sat, 29-Aug-87 20:24:39 EDT Article-I.D.: mimsy.8258 Posted: Sat Aug 29 20:24:39 1987 Date-Received: Sun, 30-Aug-87 10:04:53 EDT References: <261@calyx.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In article <261@calyx.UUCP> usenet@calyx.UUCP (USENET admin) writes: [program had] >struct junk { > int a; > int b; >} main(argc,argv) ... [due to a missing semicolon] >It compiled fine. Lint said nothing. But the output was garbage: it seems >that the missing semi-colon after the struct definition caused argc >to be given the value of argv, and argv got the value of the environment >varible pointer. This declares `main' as a structure-valued function. It is not surprising that lint did not notice anything odd about this; some improved lints may understand that main should return an integer, or not return at all, but these are no doubt rare. >Now the kicker is that this doesn't occur *anywhere else* (NCR Tower XP >running some SYSV-ish release, uVax II under Ultrix V1.2A, various Xenix >systems we have lying around). The program runs beautifully, even though >it shouldn't. Why? The only reason it did not run on the RT is that the parameter passing mechanism for structure-valued functions differs there. On these other machines, the compilers use local static memory for the structure return value, so that the call sequence works even if the caller neglects to declare a function properly. (This has other disadvantages, though.) >Better yet, is there some way to make lint tell me about this? Try including #ifdef lint thing_to_call_main() { exit(main(0, (char **)0); } #endif somewhere in the program so that lint will compare the return value of main with the argument type for exit(). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: seismo!mimsy!chris