Path: utzoo!utgpu!water!watmath!clyde!rutgers!ucsd!ucbvax!hplabs!hpcea!hpfcdc!hpfclq!cunniff From: cunniff@hpfclq.HP.COM (Ross Cunniff) Newsgroups: comp.sys.amiga Subject: Amiga programmer's hint $14 Message-ID: <4230019@hpfclq.HP.COM> Date: 8 Feb 88 22:38:42 GMT Organization: Hewlett-Packard Lines: 50 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. This means that the compiler implicitly assumes that it is returning an int. On compilers which use 32-bit ints, this is no problem. If you are using 16-bit ints, this will Guru on a machine with $C000000 memory, but *NOT* on a stock 512k Amiga. Why? Well, since OpenLibrary returns an int (as far as the compiler knows), the compiler just uses the *lower 16 bits* of the return value when it stuffs it into IntuitionBase. This is just ducky on a 512K machine. It's not so nice on a machine with more. The solution? #include struct IntuitionBase *IntuitionBase; main() { struct Library *OpenLibrary(); /* NOTE THE ADDITION OF THIS DECL! */ IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 33L ); JRandomIntuitionCall( .... ); } (I believe that the Manx compiler has a header file that defines the return value of calls such as OpenLibrary; I think it may be called ). Ross Cunniff Hewlett-Packard System Sofware Operation ...{ucbvax,hplabs}!hpda!cunniff cunniff%hplabs@hpda.ARPA