Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!umd5!purdue!gatech!mcnc!rti!sas!toebes From: toebes@sas.UUCP (John Toebes) Newsgroups: comp.sys.amiga Subject: Re: Amiga programmer's hint $14 Summary: It is only a problem for Manx - Lattice checks for the error. Message-ID: <340@sas.UUCP> Date: 19 Feb 88 14:46:39 GMT References: <4230019@hpfclq.HP.COM> Organization: SAS Institute Inc.,Cary NC,25712 Lines: 37 In article <4230019@hpfclq.HP.COM>, cunniff@hpfclq.HP.COM (Ross Cunniff) writes: > For those of you who are using the Manx compiler (and perhaps for > those of you using 16-bit ints with the Lattice compiler), here's > a tip to help you avoid the Guru on machines with more that 512K. > This really happened to a friend of mine (we spent an entire WEEKEND > sorting this out; I would've seen it sooner, but Lattice promotes > bad programming practices :-< ). > Q. What's wrong with this program? > #include > struct IntuitionBase *IntuitionBase; > main() > { > IntuitionBase = (struct IntuitionBase *) > OpenLibrary( "intuition.library", 33L ); > JRandomIntuitionCall( .... ); > } > A. OpenLibrary is not declared explicitly as returning a > pointer. Under 4.0 (which supports short integers) the compiler will complain with error 101 whenever you do this. I have seen too many people get bit by this on the PC to let it happen on the Amiga with Lattice. The basic rule is that if you ever convert a 16 bit entity to a pointer *REGARDLESS OF ANY CAST* it will issue the error message. This will catch almost all of the errors of this type (only one it can't is if you do it through indirect pointers in a called subroutine or in assembler - but then again it isn't apparent from the source code anyway). There is also a compiler switch -cf that will have the compiler scream if you ever call anything for which there is no prototype. Personnaly, I always compile with the switch and demand that the compile proceed without warnings, but I like the compiler to find my errors instead of having to wait for the GURU to find them :-) /*---------------------All standard Disclaimers apply---------------------*/ /*----Working for but not officially representing SAS or Lattice Inc.-----*/ /*----John A. Toebes, VIII usenet:...!mcnc!rti!sas!toebes-----*/ /*------------------------------------------------------------------------*/