Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!MCIRPS2.MED.NYU.EDU!root From: root@MCIRPS2.MED.NYU.EDU Newsgroups: comp.sys.sgi Subject: uncanny casting coercion Message-ID: <9005310035.AA05275@mcirps2.med.nyu.edu> Date: 30 May 90 22:31:44 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 85 X-Unparsable-Date: Wed, 30 May 90 17:35:16 DSD Some observation about typing in sgi's compiler: Observation 1) .............. char *fgets(s,n,stream); et al return EOF on end of file and a NULL pointer in s . The compiler will not allow a test if(EOF==fgets(s,n,stream)) { ... I had to do if((char *)EOF==fgets(s,n,stream)) { ... The MAN says : -------------------- DIAGNOSTICS If end-of-file is encountered and no characters have been read, no characters are transferred to s and a NULL pointer is returned. If a read error occurs, such as trying to use these functions on a file that has not been opened for reading, a NULL pointer is returned. Otherwise s is returned. ----------------------- Should I test s or fgets ? Why does fgets return a char * ? Observation 2) .............. An ANSI C char decl: MyFunction(char *Arg) { if(arg[0]==NULL)CallError(); } VS: MyFunction(char Arg[]) { if(arg[0]==NULL)CallError(); } A K&R 1 char decl: MyFunction(Arg) char *Arg; { if(arg[0]==NULL)CallError(); } MyFunction(Arg) char Arg[]; { if(arg[0]==NULL)CallError(); } The ANSI form MyFunction(char *Arg) produces a compiler complaint on the == test. Which is the most apopropriate form to use, or am I missing somthing. Why should the compiler complain, or is ansi typeing of pointers, arrays,and array pointers different in a basic way ? Cheers, Dan. c -- +-----------------------------------------------------------------------------+ | karron@nyu.edu Dan Karron | | . . . . . . . . . . . . . . New York University Medical Center | | 560 First Avenue \ \ Pager <1> (212) 397 9330 | | New York, New York 10016 \**\ <2> 10896 <3> | | (212) 340 5210 \**\__________________________________________ | +-----------------------------------------------------------------------------+