Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!tness7!petro!swrinde!dpmizar!com50!ems!pwcs!stag!daemon From: stdnet@stag.UUCP Newsgroups: comp.sys.atari.st Subject: A ghost in the house Message-ID: <515@stag.UUCP> Date: 7 Jul 88 19:32:54 GMT Sender: daemon@stag.UUCP Lines: 85 From: dynasoft!john@stag.UUCP (John Stanley) This normaly would have been sent as a personal email response, but since it effects all users of Mark Johnson's C (MJC) compiler I decided to post this to the net. --- Hi Steve! In comp.sys.atari.st, thelake!steve@stag.UUCP (Steve Yelvington) writes: > >I compiled a directory lister with Mark Johnson C, version 2.0. >It works just fine, but at the end of the directory, it prints out a >message on the console: "(no more files)". > >This message is nowhere to be found in my program or in the MJC library. >So I figure that either it is coming from GEMdos, or I have a friendly >ghost. I want it to go away. Steve, I guess you could say I'm the "friendly ghost". :) The message you mentioned is one of the standard error code messages in my JSH command shell. I'm assuming you're using JSH? When a stand alone program returns a negative exit code, JSH interprets it as one of the standard GEM/BIOS/XBIOS error codes and prints out a message. My guess is that you exit the program by just falling thru the bottom brace in main() rather than issuing a return(0) or exit(0). What happens then is a standard ambiguity/problem with the C language. Many textbook programing examples show a main() procedure that just ends. But, some also show the program using return(n) at the end of the program to return some positive condition code or negative error code. Unfortunately, there is -no- way to implement the standard crt0() function (the startup code that actualy calls main() -and- the code which determines what exit value to return to the system) in such a way that it can tell if you return() or just end out of main(). (Note: some compilers actualy force a phantom return(0) at the end of main to avoid this problem...) In MJC, this means that if you don't use exit or return at the end of main(), your program will 'return' to crt0() with whatever happens to be in the r0/d0 register at the time. In your case, this happens to be the return code from the Fsnext gemdos call which ended your directory scan. Asside note: I disagree with the implementation of the startup code that MJC uses, but I can easily see how Mark came to the conclusions he did about how it should be written. The -only- universaly acceptable way to write C main() functions is to use return(0) or exit(0) as a normal termination, and to use exit(n) to return an error or result code number to the system. If you just fall thru to the bottom brace, or if you try using return(n) with anything but 0, your program is not portable and will fail in various ways depending on the compiler and/or system. >One of the local programmers (John Osawa, author of the Schizo desk >accessory) tried my code with Mark Williams C and got no such message. >He suggested that MJC's startup code may throw a switch, and mentioned >something about Perror. I thumbed through "Atari ST Application >Programming" (Pollack and Weber), but found no references to Perror. >It's not in osbind.h. I found nothing like it in the MJC startup routines, >either. To the best of my knowledge, the MWC crt0() code totaly ignores the return value from main() and requires that any return value other than zero be returned using exit(n). > >So: What is Perror? How do I shut off this message? > Excelent programmer that he is, John Osawa is taking a long shot guess and, in this case, missing... Perror (a standard C function) has nothing to do with your phantom so I'll skip it for the moment. To avoid this problem, just exit your main() routine using return(0) or exit(0). --- John Stanley (dynasoft!john@stag.UUCP) Software Consultant / Dynasoft Systems